You are here: Home > Technical Articles > MS SQL Server - Create Table Only If Does Not Exist
Script creates table only if it does not exist in the database.
PRINT 'Create Table: events_log'
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[events_log]') AND type in (N'U'))
BEGIN
CREATE TABLE "events_log"(
el_user_guid uniqueidentifier,
el_event varchar(128),
el_event_type tinyint,
el_time datetime
)
END
GO
Published On: 02 Aug 2009
MS Sql Server - Create Table If It Already Does Not Exist
Script creates table only if it does not exist in the database.
PRINT 'Create Table: events_log'
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[events_log]') AND type in (N'U'))
BEGIN
CREATE TABLE "events_log"(
el_user_guid uniqueidentifier,
el_event varchar(128),
el_event_type tinyint,
el_time datetime
)
END
GO
Published On: 02 Aug 2009

