Monday, January 6, 2025
HomeProgrammingHow to Drop a Table If It Exists in SQL Server

How to Drop a Table If It Exists in SQL Server

o drop a table only if it exists, use the following SQL statement:

sql
IF OBJECT_ID('TableName', 'U') IS NOT NULL
DROP TABLE TableName;
  • OBJECT_ID: Checks if the table exists.
  • DROP TABLE: Deletes the table if it is found.
See also  JSON Example

Replace TableName with the actual name of your table.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x