The drop TABLE command is used to delete a table or all rows in a table. The syntax format is:
drop TABLE "TableName"
Here's an example:
drop table employee;
To delete the entire table (including all rows), you can use the drop TABLE command to add tablename. The drop TABLE command is not the same as deleting all records in a table:
Tip "Cannot delete object ' Orders ' because the object is being referenced by a FOREIGN key constraint" because it is simply not irritable, it is referenced by foreign keys in other tables, so it cannot be deleted, so you just need to find out which table's foreign keys reference the table's fields. Can be solved by system functions (SQL Server system functions provide a very complete function to find and solve many problems in place of us).
The code is as follows |
Copy Code |
Select Fk.name,fk.object_id,object_name (fk.parent_object_id) as Referencetablename From Sys.foreign_keys as FK Join sys.objects as O on fk.referenced_object_id=o.object_id where o.name= ' referenced table name ' |
The above SQL statement can obtain which foreign key references a table, and also shows the table name of the foreign-key table. You can delete a foreign key by executing the following statement with the table name and foreign key name of the foreign key table.
ALTER table dbo. Referenced table name DROP CONSTRAINT FOREIGN Key Name