IF NOT EXISTS
(
    SELECT *
    FROM dbo.sysobjects
    WHERE id = OBJECT_ID(N'[dbo].[HIO_Prescriptions]')
          AND OBJECTPROPERTY(id, N'IsUserTable') = 1
)
BEGIN
    CREATE TABLE [dbo].[HIO_Prescriptions]
    (
        [Id] [BIGINT] IDENTITY(1, 1) NOT NULL,
        [PrescriptionId] [BIGINT] NULL,
        [SendStatus] [TINYINT] NULL,
        [InsertDate] [SMALLDATETIME] NULL,
        [SendDate] [SMALLDATETIME] NULL,
        [ErrorCode] [INT] NULL,
        [ErrorMessage] [NVARCHAR](MAX) NULL,
        [ResultId] [BIGINT] NULL,
        CONSTRAINT [PK_HIO_Prescriptions]
            PRIMARY KEY CLUSTERED ([Id] ASC)
    ) ON [PRIMARY];
    ALTER TABLE [dbo].[HIO_Prescriptions]
    ADD CONSTRAINT [DF_HIO_Prescriptions_InsertDate]
    DEFAULT (GETDATE()) FOR [InsertDate];
END;