IF NOT EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[DKStatSubmitLog]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[DKStatSubmitLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LogType] [smallint] NOT NULL,
	[DateStamp] [datetime] NOT NULL,
	[FK_HotelCustomerNumber] [int] NOT NULL,
	[FK_UserIdNumber] [int] NOT NULL,
	[XML] [varchar](max) NOT NULL,
	[Year] [int] NOT NULL,
	[Month] [int] NOT NULL,
	[ResultErrorCode] [int] NULL,
	[ResultErrorDescription] [varchar](500) NULL,
 CONSTRAINT [PK_DKStatSubmitLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_DKStatSubmitLog_Customer')
ALTER TABLE [dbo].[DKStatSubmitLog]  WITH CHECK ADD  CONSTRAINT [FK_DKStatSubmitLog_Customer] FOREIGN KEY([FK_HotelCustomerNumber])
REFERENCES [dbo].[Customer] ([CustomerNumber])
GO

ALTER TABLE [dbo].[DKStatSubmitLog] CHECK CONSTRAINT [FK_DKStatSubmitLog_Customer]
GO

IF NOT EXISTS (SELECT * FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_DKStatSubmitLog_Personel')
ALTER TABLE [dbo].[DKStatSubmitLog]  WITH CHECK ADD  CONSTRAINT [FK_DKStatSubmitLog_Personel] FOREIGN KEY([FK_UserIdNumber])
REFERENCES [dbo].[Personel] ([UserIDNumber])
GO

ALTER TABLE [dbo].[DKStatSubmitLog] CHECK CONSTRAINT [FK_DKStatSubmitLog_Personel]
GO