Three magic points you need to know on Delete SQL query

SQL query Delete in DB2

The DELETE SQL query deletes a specific row you want or all table rows you can delete. The below are some magic points you need to know before you DELETE a row from Table. Using Delete Statements always my favorite statement, delete removes data from your chosen table.

That’s right; you go to all that effort crafting designs, building physical models, and coding a variety of tools to create and manage your data, and with one little statement you can remove the lot.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 1,735 other followers

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 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



Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.