SQL DROP COMMAND


SQL Drop Command | SQL Tutorial | Minigranth

SQL DROP Command : Introduction

  • SQL DROP Command is also a SQL DDL Command and is used to perform same functionality as TRUNCATE command. i.e. to delete the existing table completely from the database leaving nothing behind.
  • It means, all the values, attributes, rows, column and overall structure of the table is deleted completely.
  • If we wish to insert values in the same table, it need to be recreated first and then only the values can be inserted.
  • DROP Command once executed cannot be rolled back. It means, once the table is deleted, it cannot be retrieved again.

SQL DROP Command : Syntax

  • The syntax for SQL DROP Command is quiet similar to that of TRUNCATE command except for the DROP keyword that is used in DROP command. 

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

SQL DROP Command : Example

  • Consider the student_details and teacher_details table over which we need to perform DROP command.
Table : student_details
This image describes the select query results.

Table : teacher_details
This image describes the select query results.

Example-1 : We wish to delete the student_details table. It can be done by executing below query.

Query : DROP Table student_details;

Output : No table to display.

Example-2 : We wish to delete the teacher_details table. It can be done by executing below query.

Query : DROP Table teacher_details;

Output : No table to display.

NOTE : As the structure of table is deleted completely, If we need to insert values in the table again, it cannot be done without creating a new table. Hence, new table needs to created first and then values to the table can be inserted through INSERT command.