DROP TABLE Statement In SQL

DROP TABLE Statement in SQL

For Best view of the content : click here

DROP TABLE Statement in SQL

SQL DROP TABLE statement is used to remove table in a database. When you use the SQL DROP TABLE statement to remove a table, the database engine deletes all objects associated to that table including data, table structure, indexes, constraints, triggers and maybe privileges.

DROP TABLE Statement

The Drop Table command of SQL lets you drop a table from the database.

That is, to drop a table items, you need to write : The syntax for using a Drop Table command is :

Once this command is given, the table name is no longer recognized and no more commands can be given on that object.

DROP TABLE IF EXISTS Statement

Syntax :

DROP TABLE IF EXISTS command of SQL lets you drop a table from the database but first it check the existence of a table in database. If the table does not exists then the DROP TABLE statement is not executed so no error occurs.

For instance, consider the following query :

The IF EXISTS clause of DROP TABLE first checks whether the given table exists in the database or not. If it does, then it drops the mentioned table from the database.

The above query will first check for existence of players table in current database. If it exists, then it (table players) will be dropped from the database.

Practice Question

Q 1. Write the correct SQL statement to delete a table called Student.

You can comment the answer

TRUNCATE TABLE Statement

Syntax

The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.

DROP TABLE Statement video credit : caleb curry

SQL DROP TABLE video

DROP TABLE Statement video credit : Gate Smashers

Difference between Delete, Drop & Truncate in SQL

MySQL Drop Database SQL DROP TABLE Statement

Originally published at https://kamalsinghstarbooks.xyz.