How to Write Delete SQL Query Correctly

The DELETE SQL query deletes a specific row you want or all table rows you can delete.


Delete SQL Query

The below are some magic points you need to know before you DELETE a row from Table. 

Using Delete Statements always my favorite statement.

The delete removes data from your chosen table.

You go to all that effort crafting designs, building physical models, and coding a variety of tools to create and manage your data.

With one little statement you can remove the lot.

Okay, It removes unwanted data from a table. The delete statement takes this basic form:

Delete from tablename Where criteria is are met

For those of you who’ve used other databases that are somewhat lax about the standard and syntactical correctness, the word from is not optional.

As with the other DML statements, the where clause is optional. By not specifying a where clause, all rows from a table will be removed.

Using a where clause limits the rows deleted to those that match the specified criteria.

Related : 238 top SQL queries

A simple example using the where clause is the following:

Delete from employee
Where joindate > '2010-01-01'

One interesting aspect of the DB2 delete and update implementation is that you’ll see a warning if the criteria you specify don’t match any rows; that is

if your delete statement won’t actually delete any rows. You’ll see this warning:

SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000

Related: Real usage for Fetch 1 row in DB2 SQL

Resources: IBM Knowledge center

Related Posts