Below are some methods to check the existence of table in
SQL Server database.
Method 1 :-
IF OBJECT_ID ('<database_name>.<schema_name>.<table_name>') IS NOT NULL
BEGIN
PRINT 'Table exist'
END
ELSE
BEGIN
PRINT 'Table does not exist'
END
Method 2 :-
SELECT *
FROM sys.objectsWHERE name = '<table name>'
AND type = 'U' -- for user defined tables
No comments:
Post a Comment