The SQL command that uses the delete table is the same as the command to delete the data, except that the object is deleted from the table.
The syntax is as follows: DROP table name
Generally before deleting a table, it is necessary to determine that the table does not exist, the existence is deleted, does not exist do not execute any code.
Code 1 and Code 2 can also delete the table.
In addition, it is important to emphasize that before deleting a table, you must first delete the table containing the foreign key, and if you delete the primary key table directly from the foreign key reference, you will get an error.
Code Listing 1:
UsePersonInfoGO--if an object named employee is found in the Personinfo database system object, and the type is tableIF EXISTS(SELECT * fromSys.sysobjectsWHEREName= 'Employee' andXtype= 'U')--then delete the employeeDROP TABLEEmployeeGO
Results:
Code Listing 2:
Use PersonInfo GO -- If a table named person is found in the Personinfo database table Object IF EXISTS (SELECT*fromWHERE='person' ) )-- DeletepersondropTABLE personGO
Results:
4-sql Server 2008 using the SQL statement to delete a table