IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[SMSImportFileLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  CREATE TABLE [dbo].[SMSImportFileLog]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [FileName] [varchar](500) NOT NULL,
    [FileNameConvertedFile] [varchar](500) NOT NULL,
    [FileCreateDate] [datetime] NOT NULL,
    [FileLastAccessDate] [datetime] NOT NULL,
    [FileLastModification] [datetime] NOT NULL,
    [ImportDateStamp] [datetime] NOT NULL,
    [NumberOfLines] [int] NOT NULL,
    CONSTRAINT [PK_SMSImportLog] PRIMARY KEY CLUSTERED 
    (
      [Id] ASC
    )
  ) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[SMSImportFileContentLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[SMSImportFileContentLog]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [LogType] [smallint] NOT NULL,
    [LineIndex] [int] NOT NULL,
    [FK_SMSImportFileLogId] [int] NOT NULL,
    [FK_TransactionId] [int] NULL,
    [LineRaw] [varchar](5000) NOT NULL,
    [Field1] [varchar](100) NULL,
    [Field2] [varchar](100) NULL,
    [Field3] [varchar](100) NULL,
    [Field4] [varchar](100) NULL,
    [Field5] [varchar](100) NULL,
    [Field6] [varchar](100) NULL,
    [Field7] [varchar](100) NULL,
    [FIeld8] [varchar](100) NULL,
    [Field9] [varchar](100) NULL,
    [Field10] [varchar](100) NULL,
    [ErrorCode] [INT] NOT NULL,
    CONSTRAINT [PK_SMSImportFileContentLog] PRIMARY KEY CLUSTERED 
    (
      [Id] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[SMSImportFileContentLog]  WITH CHECK ADD  CONSTRAINT [FK_SMSImportFileContentLog_SMSImportFileLog] FOREIGN KEY([FK_SMSImportFileLogId])
  REFERENCES [dbo].[SMSImportFileLog] ([Id])

  ALTER TABLE [dbo].[SMSImportFileContentLog] CHECK CONSTRAINT [FK_SMSImportFileContentLog_SMSImportFileLog]

  ALTER TABLE [dbo].[SMSImportFileContentLog]  WITH CHECK ADD  CONSTRAINT [FK_SMSImportFileContentLog_Transactions] FOREIGN KEY([FK_TransactionId])
  REFERENCES [dbo].[Transactions] ([TransactionNumber])

  ALTER TABLE [dbo].[SMSImportFileContentLog] CHECK CONSTRAINT [FK_SMSImportFileContentLog_Transactions]
END