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-

IDNameAGEADDRESSSalary
001Rahul23Kota20000.00
002Clinton22Mumbai15000.00
003Kamal31Delhi25000.00
004Chitra28Kanyakumari65000.00
005Santanu26Madhya Pradesh38500.00
006Savitri24Bhopal4500.00
007Manii30Indonesia15000.00

Example 1:

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

EMPLOYEES table will have the below records:

IDNameAGEADDRESSSalary
001Rahul23Kota20000.00
002Clinton22Mumbai15000.00
003Kamal31Delhi25000.00
004Chitra28Kanyakumari65000.00
005Santanu26Madhya Pradesh38500.00
007Manii30Indonesia15000.00

Example 2-

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

Output:

IDNameAGEADDRESSSalary
002Clinton22Mumbai15000.00
003Kamal31Delhi25000.00
004Chitra28Kanyakumari65000.00
005Santanu26Madhya Pradesh38500.00
007Manii30Indonesia15000.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.


You may also like