IF NOT (EXISTS
(
    SELECT *
    FROM sysobjects
    WHERE name = 'IHIOSavedPrescriptionDetail'
)
       )
BEGIN

    CREATE TABLE [dbo].[IHIOSavedPrescriptionDetail]
    (
        [Id] [UNIQUEIDENTIFIER] NOT NULL,
        [PrescriptionId] [UNIQUEIDENTIFIER] NULL,
        [GenericCode] [VARCHAR](5) NULL,
        [IRCCode] [VARCHAR](16) NULL,
        [GoodsCode] [VARCHAR](15) NULL,
        [ShapeCode] [SMALLINT] NULL,
        [ConsumptionCode] [VARCHAR](20) NULL,
        [ConsumptionInstructionCode] [VARCHAR](20) NULL,
        [NumberOfPeriod] [INT] NULL,
        [IsOutOfPrescription] [BIT] NULL,
        [OrderCount] [FLOAT] NULL,
        [DeliverCount] [FLOAT] NULL,
        CONSTRAINT [PK_IHIOSavedPrescriptionDetail]
            PRIMARY KEY CLUSTERED ([Id] ASC)
    ) ON [PRIMARY];

    ALTER TABLE [dbo].[IHIOSavedPrescriptionDetail]
    ADD CONSTRAINT [DF_IHIOSavedPrescriptionDetail_Id]
        DEFAULT (NEWID()) FOR [Id];

    ALTER TABLE [dbo].[IHIOSavedPrescriptionDetail] WITH CHECK
    ADD CONSTRAINT [FK_IHIOSavedPresciptionDetail_IHIOSavedPrescription]
        FOREIGN KEY ([PrescriptionId])
        REFERENCES [dbo].[IHIOSavedPrescription] ([Id]) ON DELETE CASCADE;

    ALTER TABLE [dbo].[IHIOSavedPrescriptionDetail] CHECK CONSTRAINT [FK_IHIOSavedPresciptionDetail_IHIOSavedPrescription];
END;