{{ model.title }}

by {{ model.createdBy }}
This script is an example on how to check to see if items exists. - SQL Table Exists - SQL Column Exists
code
-- Just add "NOT" to invert the checks

-- Check Table Exists
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = N'schemaName' AND  TABLE_NAME = N'tableName')
BEGIN
	-- Table Exists
END

-- Check Column Exists
IF EXISTS (SELECT 1 FROM [sys].[columns] WHERE [Name] = N'columnName' AND [object_id] = OBJECT_ID(N'schemaName.tableName'))
BEGIN
	-- Column Exists
END

-- Check Column Default Exists
IF EXISTS (SELECT * FROM [sys].[all_columns] c JOIN [sys].[tables] t on t.[object_id] = c.[object_id] JOIN [sys].[schemas] s on s.[schema_id] = t.[schema_id] JOIN [sys].[default_constraints] d on c.[default_object_id] = d.[object_id] WHERE t.[name] = 'tableName' AND c.[name] = 'columnName' AND s.[name] = 'schemaName')
BEGIN
	-- Column Default Exists
END

-- Check Stored Procedure Exists
IF  EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND OBJECT_ID = OBJECT_ID('schema.name'))
BEGIN
	-- Stored Procedure Exists	
END

-- Check Function Exists
IF EXISTS (SELECT 1 FROM [Information_schema].[Routines] WHERE [Specific_schema] = 'schemaName' AND [specific_name] = 'functionName' AND [Routine_Type] = 'FUNCTION')
BEGIN
	-- Function Exists
END