SQL DELETE | Delete Rows in SQL | Learn SQL

SQL Delete

The SQL DELETE Statement is used to delete data (rows)  from a table. we can say it is used to remove records from a table.

Note: DELETE FROM command cannot delete any rows of data that would violate FOREIGN KEY or other constraints.

Syntax of a SQL DELETE Statement

SQL Delete | Tech-Mirror
SQL Delete | Tech-Mirror

Note: The WHERE clause in the sql delete command is not necessary or optional and it identifies the rows in the table that gets deleted.If you do not include the WHERE clause all the rows in the table is deleted, so be careful while writing a DELETE query without WHERE clause. Once Delete command is fire you can not get back data.

 SQL DELETE Example

To delete a student with id 10 from the student_master table, the sql delete query would be like,

To delete all the rows from the student_master table, the query would be like,


SQL TRUNCATE Command/Statement

The SQL TRUNCATE statement is used to delete all the rows from the table and free the space containing the table.

Syntax for TRUNCATE table

SQL TRUNCATE Example

To delete all the rows from student_master table, the sql query would be like,


Difference between DELETE and TRUNCATE 

Delete Truncate
Delete command deletes only the rows from the table based on the condition given in the where clause or deletes all the rows(data) from the table if no condition is specified. But it does not free the space containing the table. Truncate command is used to delete all the rows from the table and free the space containing the table.

SQL DROP Command

The SQL DROP statement is used to remove an object from the database like table, columns etc. If you drop a table, all the data related to the table is deleted and the table design or structure is removed from the database. Once a table is dropped we cannot get it back, so be careful while using DROP command.

Syntax to drop a table

SQL DROP Example

To drop the table student_master, the sql query would be like,


For More SQL Order by Clause

Leave a Reply

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