How to delete a SQL Server table? How to drop a table without checking if the table exists? Assume the object is already in the database.
How to delete a SQL Server table from the database with a query?
For example, let’s consider a table named dbo.SALES, and use this query to drop the table :
DROP TABLE [dbo].[SALES];
As no existence check is performed, if the SQL server displays this error, then the table doesn’t exists in the current database.
SQL Server Error:
« Msg 3701, Level 11, State 5, Line 1
Cannot drop the table ‘SALES’, because it does not exist or you do not have permission. »
You want to DROP a table from your SQL Server database, but using directly the SQL command DROP TABLE followed by the table name, the DBMS system is throwing an error because the table does not exist. The solution is to test the existence of the table using a simple SQL query.
The previous article is on how to modify a SQL Server table.
Use the SQL script example to check the existence before drop a table using the EXISTS function.