navigation
SQL

how to check table exists in SQL Server?

| | SQL

Best way to use an INFORMATION_SCHEMA view. These views are most standard across the plateform.


To check if a table exists use:


IF (EXISTS (SELECT * 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'UserLogin'))
BEGIN
--Do Stuff
print 'hello'
END


Output:

hello