Drop If Exists Syntax
Revision as of 16:30, 1 September 2016 by RobertSter (talk | contribs)
SQL Server 2016
for a permanent table dbo.Scores you can use
IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL DROP TABLE dbo.Scores;
Or, for a temporary table you can use
IF OBJECT_ID('tempdb.dbo.#T', 'U') IS NOT NULL DROP TABLE #T;
Other methods:
if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'Scores' AND TABLE_SCHEMA = 'dbo') drop table dbo.Scores;