1. By using the OBJECT_ID() function
If OBJECT_ID('my_table', 'U') is not null
BEGIN
print 'my_table Table exists'
END
2. By using the INFORMATION_SCHEMA.TABLES
If exists (SELECT * FROM INFORMATION_SCHEMA.TABLES Where table_name = 'my_table')
BEGIN
print 'my_table Table exists!'
END
3. By using sys.Objects Catalog view
If exists(Select * from sys.objects where object_id = OBJECT_ID('my_table') and type = 'U')
BEGIN
print 'my_table Table exists!'
END
Read: https://docs.microsoft.com/en-us/sql/relational-databases/system-information-schema-views/system-information-schema-views-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!