IF NOT EXISTS
(
    SELECT *
    FROM sysobjects
    WHERE name = 'ChainSupplyHIXInvoice'
)
BEGIN
    CREATE TABLE [dbo].[ChainSupplyHIXInvoice]
    (
        [Id] [NUMERIC](18, 0) IDENTITY(1, 1) NOT NULL,
        [InvoiceId] [NUMERIC](18, 0) NULL,
        [Status] [TINYINT] NULL,
        [InsertDate] [DATETIME] NULL,
        [ResultDate] [DATETIME] NULL,
        [ExceptionCode] [NVARCHAR](MAX) NULL,
        [ExceptionMessage] [NVARCHAR](MAX) NULL,
        [ExceptionStacktrace] [NVARCHAR](MAX) NULL,
        [PayloadClass] [NVARCHAR](MAX) NULL,
        [Type] [INT] NULL,
        [ConversationId] [NVARCHAR](MAX) NULL,
        [ResultId] [NVARCHAR](200) NULL,
        CONSTRAINT [Pk_ChainSupplyHIX_iNVOICE]
            PRIMARY KEY CLUSTERED ([Id] ASC)
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];

    ALTER TABLE [dbo].[ChainSupplyHIXInvoice]
    ADD CONSTRAINT [DF_ChainSupplyHIXInvoice_InsertDate]
    DEFAULT (GETDATE()) FOR [InsertDate];
END;