In this article we will see three simple ways to delete a table from a database in SQL Server 2008.
Deleting table from template Explorer:
For any operations in the database tables, SQL Server Management Studio has already provided you with templates.
So let us see how to delete a table from the template available in the studio. For this open a new query window and select View --> Template Explorer.
Go to the table node in the explorer.
Now drag the template "Drop Table" to the query window.
-- Drop Table template
IF EXISTS (
ON sys.tables.schema_id = sys.schemas.schema_id
WHERE sys.schemas.name = N'<schema_name, sysname, your_schema_name>'
AND sys.tables.name = N'<table_name, sysname,
DROP TABLE <schema_name, sysname, your_schema_name>.<table_name, sysname, your_table_name>
Make the necessary changes and execute the query by pressing F5.
Deleting table through wizard:
Most common methods used today is through the Object Explorer.
Right click the table you want to delete in a database and select the delete option from the context menu.
The dialog box that appears after clicking the delete option is shown below:
We can look for dependencies of this table with other object as shown below:
Confirming the action by clicking the OK button will delete the database from SQL Server.
Deleting table from Query:
The query to delete the table from a database is as follows:
DROP TABLE table_name
DROP TABLE emp_sal