SQL DELETE COMMAND


SQL Delete Command | SQL Tutorial | Minigranth

SQL DELETE Command : Introduction

  • The SQL DELETE Command is a type of SQL SDML Command and is used to delete pre-existing records or values or rows of the tables present in the database.
  • The advantage of using SQL DELETE Command is, only the values or records from table gets deleted and the overall structure(containing attributes) remains untouched. Let’s check the syntax first and then we will try to implement this command with an example.

SQL DELETE Command : Syntax

  • The syntax for SQL DELETE Command is pretty simple. There are two possible basic syntax based on conditions. Below is their illustration.

This image describes the basic syntax of sql delete command that is used in sql.
SQL DELETE Command : Syntax

OR

This image describes the basic syntax of delete command that is used in sql.
SQL DELETE Command : Syntax

SQL DELETE Command : Example

  • Consider the table of student_details that was created earlier.

Table : student_details

This image describes the select query results.

Example-1 : If we wish to delete the whole student_details table, it can be done by executing below query.

Query : DELETE FROM student_details;

Output : No rows to display.

Example-2 : If we wish to delete a particular row from the student_details, it can be done by executing below query.

Query : DELETE FROM student_details WHERE Name = ‘Rakesh’;

Output :

  This image describes the select query results.  
NOTE : As the structure of table remains untouched even after deletion of table data. If we need to insert values in the table again, it can be done without creating a new table and by directly inserting values to the table through INSERT command.