SQL Drop Table Query Statement Example

Learn how to delete a SQL table from database permanently, SQL Drop Table Query Example.

Here you learn how to drop a table in SQL Server drop TABLE [schema-Name].[table-name].

Remember that once you drop a table all data in that table will be lost, so be careful before executing Drop statement in SQL Server.

Drop is like you are deleting the object permanently from SQL Server, but in SQL Delete is considered as query statement.

Drop Table in SQL Database

So, here is how you can Drop a table in SQL.

// drop TABLE [schemaName].[tableName]
           
drop TABLE [dbo].[tbTeacher]

If you want to just delete the data , think of delete or truncate but don’t drop the table.

Drop table exception:

If the table is referenced by FOREIGN KEY Constraint, then it will not allow you to drop the table, and throw an exception "Could not drop object 'table' because it is referenced by a FOREIGN KEY constraint"

If you get the above error while dropping a table, you need to delete the Foreign Key Constraint first, then will be able to drop the table.

ALTER TABLE [TableName]
DROP CONSTRAINT FK_ConstName; 
ALTER TABLE ClassStudentMap
DROP CONSTRAINT FK_ClassStudentMap_ClassRoom;

While specifying schema name in drop table query, you should have permission on that schema, for example, if you try to drop a table that reside under account schema like account.tablename, if you have permission or you should be system admin.

You should consider taking backup of all objects and data before you execute drop table statement.

 
Hire SQL Developer
Drop Table in SQL Database
SQL Training: For any group or corporate training, please contact us at webtrainingroom(at)gmail.
SQL job Interview Questions Answers
Course in Demand
SQL database development tutorials for learning sql query, data manipulation language, working with MS SQL Server.
MS SQL Examples | Join MS SQL Course