The SQL DELETE clause is used to delete data from a database table. The simplest SQL DELETE syntax looks like this:
DELETE FROM Table1
The SQL DELETE statement above will delete all data from the Table1 table.
Most of the time we will want to delete only table rows satisfying certain search criteria defined in the SQL WHERE clause. We will use the Weather table again to illustrate how to use SQL DELETE to delete a limited number of rows from a table:
City | AverageTemperature | Date |
New York | 22 C | 10/10/2005 |
Seattle | 21 C | 10/10/2005 |
Washington | 20 C | 10/10/2005 |
New York | 18 C | 10/09/2005 |
Seattle | 20 C | 10/09/2005 |
Washington | 17 C | 10/09/2005 |
If we wanted to delete all rows containing Weather data for New York, we would use the following SQL DELETE statement:
DELETE FROM Weather WHERE City = 'New York'
Be extremely careful when using SQL DELETE, as you cannot restore data once you delete it from the table. You might want to make a backup of important data before performing delete on it.
0 comments:
Post a Comment