Home » T-SQL DELETE Query

T-SQL DELETE Query

by Online Tutorials Library

DELETE Query

The DELETE Query in T-SQL is used to delete the existing records, which we want to remove from the table. We use the WHERE clause with DELETE command to delete the rows that we have selected to delete. Otherwise the record is deleted.

Syntax:-

We combine N number of condition using the AND or OR operators.

Example:

Consider the EMPLOYEES table which has the following records-

ID Name AGE ADDRESS Salary
001 Rahul 23 Kota 20000.00
002 Clinton 22 Mumbai 15000.00
003 Kamal 31 Delhi 25000.00
004 Chitra 28 Kanyakumari 65000.00
005 Santanu 26 Madhya Pradesh 38500.00
006 Savitri 24 Bhopal 4500.00
007 Manii 30 Indonesia 15000.00

Example 1:

Below command is an example of DELETE an EMPLOYEES record, whose ID is 006–

EMPLOYEES table will have the below records:

ID Name AGE ADDRESS Salary
001 Rahul 23 Kota 20000.00
002 Clinton 22 Mumbai 15000.00
003 Kamal 31 Delhi 25000.00
004 Chitra 28 Kanyakumari 65000.00
005 Santanu 26 Madhya Pradesh 38500.00
007 Manii 30 Indonesia 15000.00

Example 2-

Below command is an example of DELETE an EMPLOYEES record, who’s Name is RAHUL-

Output:

ID Name AGE ADDRESS Salary
002 Clinton 22 Mumbai 15000.00
003 Kamal 31 Delhi 25000.00
004 Chitra 28 Kanyakumari 65000.00
005 Santanu 26 Madhya Pradesh 38500.00
007 Manii 30 Indonesia 15000.00

If we DELETE all the records from the EMPLOYEES table, we don’t need to use the WHERE clause. DELETE query will be as follows ?

EMPLOYEES table now will not have any record.


Next TopicT-SQL WHERE Clause

You may also like