Saturday, July 23, 2011

Delete From Statement


Sometimes we may wish to use a query to remove records from a table. To do so, we can use the DELETE FROM command. The syntax for this is
DELETE FROM "table_name"
WHERE {condition}

It is easiest to use an example. Say we currently have a table as below:
Table Store_Information
store_nameSalesDate
Los Angeles$1500Jan-05-1999
San Diego$250Jan-07-1999
Los Angeles$300Jan-08-1999
Boston$700Jan-08-1999

and we decide not to keep any information on Los Angeles in this table. To accomplish this, we type the following SQL:
DELETE FROM Store_Information
WHERE store_name = "Los Angeles"

Now the content of table would look like,
Table Store_Information
store_nameSalesDate
San Diego$250Jan-07-1999
Boston$700Jan-08-1999


0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server