by Dinesh Thakur Category: SQL Queries

Sometimes we may decide that we need to get rid of a table in the database for some reason. The SQL DROP TABLE statement is the SQL command that removes an entire SQL table. This command also removes one or more table definitions and all data, indexes, triggers, constraints, and permission specifications for those tables.

The SQL DROP command is used to remove an object from the database. If you drop a table, all the rows in the table is deleted and the table structure is removed from the database. Once a table is dropped we cannot get it back, so be careful while using RENAME command. When a table is dropped all the references to the table will not be valid.

Syntax: SQL> Drop Table Tablename [cascade constraint];

When you give a "drop table" command, it will not drop the table that has dependencies unless you include the "cascade" command in the statement. The database programming is written this way to make sure you know the table has dependent objects and makes you explicitly say you want to drop the table and all its dependencies.

Example:

SQL> DROP TABLE Persons;
Table
dropped

The above command will physically remove the Persons table from the database. But if this is a parent table and referring a child table then first remove the child table and then try to remove this table.

Related Articles of SQL





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.