Delete - High-Flying SQL Tips


SQL Tips

Add a Unique Constraint to a Column

CURSOR

DELETE

Dirty Reads and Phantom Reads

INSERT

Recursive SQL

ROW_NUMBER() - Automatic Paging

SELECT, FROM

SQL Default Date Format

UPDATE

WHERE

Sponsored Links

73058_New Scooba® 230 Floor Washing Robot + Free Shipping!

 

DELETE

Here we look at the Delete command in SQL.

The Delete command in SQL allows us to delete data from a table in our database. It can be used to delete one row, multiple rows and all the rows.

In our first example, we delete a row where the ProductID is equal to 12345. This query would actually delete all the rows with a ProductID of 12345, so be careful.


-- Delete any row where ProductID = '12345'
DELETE FROM Products WHERE ProductID = '12345'


The following example will delete all the data in your database table.


-- Delete all the data in the table
DELETE FROM Products


The following example will delete rows where the price is between 11.00 and 14.00, including if the price is 11.00 or 14.00.


-- Delete all the rows where the
-- price is between 11.00 and 14.00 inclusively
DELETE FROM Products WHERE Price >= '11.00' AND Price <= '14.00'