How to check table exists in SQL Server?
How to check table exists in SQL Server?
235
11-Jul-2023
Updated on 12-Jul-2023
Aryan Kumar
12-Jul-2023Sure, I can help you with that. Here are two ways to check if a table exists in SQL Server:
IF EXISTSclauseThe
IF EXISTSclause is a conditional statement that can be used to check if a table exists. The syntax for theIF EXISTSclause is as follows:SQL
The
table_nameis the name of the table that you want to check if it exists.For example, the following code will check if the
Customerstable exists:SQL
OBJECT_ID()functionThe
OBJECT_ID()function can be used to get the object ID of a table. If the table does not exist, theOBJECT_ID()function will returnNULL.The syntax for the
OBJECT_ID()function is as follows:SQL
The
table_nameis the name of the table that you want to get the object ID for.For example, the following code will check if the
Customerstable exists:SQL