In this step by step SQL Tutorial I will show you how to use Drop table statement. For the purpose of this tutorial I will use SQL Server Management Studio 2012.
You might find this tutorial if:
- You are new to SQL and DROP TABLE statements
- You would like to find out how to perform DROP TABLE using interface and T-SQL script
- You are preparing for Microsoft Certification and DROP is not what you have used before
SQL DROP TABLE is used to permanently remove table from database (without logging). You might not be able to DROP TABLE if it is referenced by another table (PrimaryKey/ForeignKey)
Below I show you how to remove table from database using SSMS interface and using T-SQL.
In the Object Explorer I open required database in this case it is AdventureWorksDW2012 then I expand Tables folder and find table which I want to remove. In this example it is dbo.Employee table.
Below I will show you how to delete (DROP) table from database using Object Explorer in SSMS 2012.
I open Object Explorer,AdventureWorksDW2012 database and from Tables folder I right click dbo.Employee.
From drop down box I select Delete.
In the Delete Object window I click OK.
This time I will show you how to drop table using T-SQL
Create new query and make sure that correct database is selected on the database drop down box on the tool bar.
SYNTAX: DROP TABLE TableName
The syntax is very simple and i below is my sample which I executed using Execute button.
NOTE: If you selected database in drop down box you could just type in query window:
DROP TABLE Employee
but it is safer to specify schema like that
DROP TABLE dbo.Employee
If you haven't selected database name or you want to execute your query against different database you can use
DROP TABLE DatabaseName.SchemaName.TableName
and below is example
Once i execute my drop table I get message that code run successfully.
Object explorer sometimes will not refresh the table list straight away. If you table didn't disappear try to refresh it. You can right click database name and click refresh (see below) or you can right click tables folder in the database and refresh on changes in tables folder.
You can see that there is no dbo.Employee table in Itcouple database.
I hope that helps you to learn and use DROP TABLE statement.