Deleting Data from Tables

The DELETE command is used to remove entire rows of data from a table. The DELETE command is not used to remove values from specific columns; a full record, including all columns, is removed. The DELETE statement must be used with caution—it works all too well. The next section discusses methods for deleting data from tables.

To delete a single record or selected records from a table, the DELETE statement must be used with the following syntax:

delete from schema.table_name
[where condition];

						DELETE FROM ORDERS_TBL
						WHERE ORD_NUM = '23A16';
					

001 001 1 row deleted.
002 002 

Notice the use of the WHERE clause. The WHERE clause is an essential part of the DELETE statement if you are attempting to remove selected rows of data from a table. You rarely issue a DELETE statement without the use of the WHERE clause. If you do, your results are similar to the following example:

DELETE FROM ORDERS_TBL;

11 rows deleted.

Caution

If the WHERE clause is omitted from the DELETE statement, all rows of data are deleted from the table. As a general rule, always use a WHERE clause with the DELETE statement.


Note

The temporary table that was populated from the original table earlier in this hour can be very useful for testing the DELETE and UPDATE commands before issuing them against the original table.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset