Back-End Development SQL basics

SQL delete statement

The SQL delete Statement is used to delete an existing records from a table.


Syntax:

Demo database: Customers

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #001,sec-19 c chd
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd

SQL delete statement examples:

Deleting Rows

To delete a row , where some column has some particular value .
Suppose we want to delete a customer row where the value for column C.id is aa22103. For this we use the following SQL delete statement:


Result:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #001,sec-19 c chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd


Deleting all table data

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

Syntac:

NOTE: Once you perform delete operation, one can not undo it. BE careful.