IF (NOT EXISTS 
	(SELECT * FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_NAME = 'pal_JobProcs'))
BEGIN
	CREATE TABLE [dbo].[pal_JobProcs] (
		[recId]      INT           IDENTITY (1, 1) NOT NULL,
		[customerDB] VARCHAR (50)  NULL,
		[procName]   VARCHAR (50)  NULL,
		[procParams] VARCHAR (250) NULL,
		[todo]       BIT           NULL,
		CONSTRAINT [PK_pal_JobProcs] PRIMARY KEY CLUSTERED ([recId] ASC)
	);
END

IF EXISTS (SELECT * 
	FROM sys.indexes 
	WHERE name='IX_SurfaceField_surfaceFieldName' 
	AND object_id = OBJECT_ID('dbo.pal_SurfaceField'))
BEGIN
	DROP INDEX [IX_SurfaceField_surfaceFieldName]
    ON [dbo].[pal_SurfaceField];
END

IF EXISTS (SELECT * 
	FROM sys.indexes 
	WHERE name='IX_SurfaceField_surfaceId' 
	AND object_id = OBJECT_ID('dbo.pal_SurfaceField'))
BEGIN
	DROP INDEX [IX_SurfaceField_surfaceId]
    ON [dbo].[pal_SurfaceField];
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_CreateSurfaceQueryTable]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_CreateSurfaceQueryTable]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SaveMultiSurfaceItemQueryTable]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SaveMultiSurfaceItemQueryTable]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetSurfaceDataItemFromLinks]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetSurfaceDataItemFromLinks]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetItemLabelValues]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetItemLabelValues]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetLabelValues]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetLabelValues]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_ExecuteJobProcs]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_ExecuteJobProcs]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_UpdateSurfaceData]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_UpdateSurfaceData]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SaveSurfaceItemQueryTable]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SaveSurfaceItemQueryTable]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetSurfaceDataFromLinks]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetSurfaceDataFromLinks]
END


