Saturday, March 12, 2016

SQL DELETE Command

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:

CityAverageTemperatureDate
New York22 C10/10/2005
Seattle21 C10/10/2005
Washington20 C10/10/2005
New York18 C10/09/2005
Seattle20 C10/09/2005
Washington17 C10/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

 
Animated Social Gadget - Blogger And Wordpress Tips