SQL delete statement

      No Comments on SQL delete statement

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


Syntax:

  • DELETE from table_name
    WHERE some_column=some_value;
    

Demo database: Customers

C.idC.nameC.contactC.address
123eed3Ramesh987654321#001,sec-19 c chd
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#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:

DELETE from Customers
WHERE C.id='aa22103'; 

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#001,sec-19 c chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#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:

DELETE from table_name;

or

DELETE * from table_name;

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

Leave a Reply

Your email address will not be published. Required fields are marked *