SIGN UP MEMBER LOGIN:
   
ARTICLE

How to delete a table in SQL Server 2008

Posted by Praveen Kumar Articles | SQL Server February 11, 2010
In this article we will see how to delete a table from SQL Server 2008.
Reader Level:

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.

1.gif

Now drag the template "Drop Table" to the query window.

--======================
-- Drop Table template
--======================
IF EXISTS (
  SELECT *
          FROM sys.tables
          JOIN sys.schemas
            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, your_table_name>'
)
  DROP TABLE <schema_name, sysname, your_schema_name>.<table_name, sysname, your_table_name>
GO

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.

2.gif

The dialog box that appears after clicking the delete option is shown below:

3.gif

We can look for dependencies of this table with other object as shown below:

4.gif

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

Example: 

DROP TABLE  emp_sal

Login to add your contents and source code to this article
This Feature is Sponsored By
post comment
COMMENT USING