SQL for Beginners
About Lesson

DELETE

The DELETE statement is used to delete rows in a table.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
DELETE FROM table_name
WHERE some_column=some_value
DELETE FROM table_name WHERE some_column=some_value
DELETE FROM  table_name 
WHERE some_column=some_value

Note! Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
delete from CUSTOMER where CustomerId=2
delete from CUSTOMER where CustomerId=2
delete from CUSTOMER where CustomerId=2

Before Delete:

After Delete:

 

Delete All Rows:

It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
DELETE FROM table_name
DELETE FROM table_name
DELETE FROM table_name

Note! Make sure to do this only when you really mean it! You cannot UNDO this statement!

 

Delete Data in the Designer Tools:

You delete data in the designer by right-click on the row and select “Delete”: