IF NOT EXISTS
(
    SELECT name
    FROM sysobjects
    WHERE name = 'CorrectionHistory'
)
BEGIN
    CREATE TABLE [dbo].[CorrectionHistory]
    (
        [id] [INT] IDENTITY(1, 1) NOT NULL,
        [PrescriptionId] [NUMERIC](19, 0) NULL,
        [Type] [SMALLINT] NULL,
        [Status] [SMALLINT] NULL,
        [Description] [NVARCHAR](MAX) NULL,
        [UserId] [SMALLINT] NULL,
        [InsertDate] [SMALLDATETIME] NULL,
        CONSTRAINT [PK_CorrectionHistory]
            PRIMARY KEY CLUSTERED ([id] ASC)
    ) ON [PRIMARY];

    ALTER TABLE [dbo].[CorrectionHistory]
    ADD CONSTRAINT [DF_CorrectionHistory_InsertDate]
    DEFAULT (GETDATE()) FOR [InsertDate];

    ALTER TABLE [dbo].[CorrectionHistory] WITH CHECK
    ADD CONSTRAINT [FK_CorrectionHistory_CorrectionHistory]
        FOREIGN KEY ([PrescriptionId])
        REFERENCES [dbo].[DrugH] ([Id_Havaleh]);

    ALTER TABLE [dbo].[CorrectionHistory] CHECK CONSTRAINT [FK_CorrectionHistory_CorrectionHistory];
END;