IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[ReservationSendLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
	CREATE TABLE [dbo].[ReservationSendLog](
		[ID] [int] IDENTITY(1,1) NOT NULL,
		[FK_RefereneNumber] [int] NOT NULL,
		[FK_GuestNumber] [smallint] NOT NULL,
		[DateStamp] [datetime] NOT NULL,
		[SendType] [int] NOT NULL,
		[Receiver] [varchar](50) NOT NULL,
		[FK_TemplateNumber] [int] NOT NULL
	 CONSTRAINT [PK_ReservationSendLog] PRIMARY KEY CLUSTERED 
	(
		[ID] ASC
	)
	) ON [PRIMARY]

	ALTER TABLE [dbo].[ReservationSendLog]  WITH CHECK ADD  CONSTRAINT [FK_ReservationSendLog_Reservations] FOREIGN KEY([FK_RefereneNumber], [FK_GuestNumber])
	REFERENCES [dbo].[Reservations] ([ReferenceNumber], [GuestNumber])

	ALTER TABLE [dbo].[ReservationSendLog] CHECK CONSTRAINT [FK_ReservationSendLog_Reservations]

	ALTER TABLE [dbo].[ReservationSendLog]  WITH CHECK ADD  CONSTRAINT [FK_ReservationSendLog_Templates] FOREIGN KEY([FK_TemplateNumber])
	REFERENCES [dbo].[Templates] ([TemplateNumber])

	ALTER TABLE [dbo].[ReservationSendLog] CHECK CONSTRAINT [FK_ReservationSendLog_Templates]

	CREATE NONCLUSTERED INDEX [IX_ReservationSendLog_1] ON [dbo].[ReservationSendLog]
	(
		[FK_RefereneNumber] ASC,
		[FK_GuestNumber] ASC,
		[SendType] ASC,
		[Receiver] ASC,
		[FK_TemplateNumber]
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

END