IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[GiftTokenProlongLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[GiftTokenProlongLog]
  (
    [FK_GiftTokenId] [int] NOT NULL,
    [ProlongDate] [datetime] NOT NULL,
    [FK_UserIdNumber] [int] NOT NULL,
    [Old_ExpireDate] [datetime] NOT NULL,
    [New_ExpireDate] [datetime] NOT NULL,
    CONSTRAINT [PK_GiftTokenProlongLog] PRIMARY KEY CLUSTERED 
    (
      [FK_GiftTokenId] DESC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[GiftTokenProlongLog]  WITH CHECK ADD  CONSTRAINT [FK_GiftTokenProlongLog_GiftToken] FOREIGN KEY([FK_GiftTokenId])
  REFERENCES [dbo].[GiftToken] ([Id])

  ALTER TABLE [dbo].[GiftTokenProlongLog] CHECK CONSTRAINT [FK_GiftTokenProlongLog_GiftToken]

  ALTER TABLE [dbo].[GiftTokenProlongLog]  WITH CHECK ADD  CONSTRAINT [FK_GiftTokenProlongLog_Personel] FOREIGN KEY([FK_UserIdNumber])
  REFERENCES [dbo].[Personel] ([UserIDNumber])

  ALTER TABLE [dbo].[GiftTokenProlongLog] CHECK CONSTRAINT [FK_GiftTokenProlongLog_Personel]
END