IF NOT EXISTS
(
    SELECT name
    FROM sysobjects
    WHERE name = 'FK_SupplementaryInsurance_DrugCondition_SupplementaryInsurance'
)
BEGIN
    ALTER TABLE [dbo].[SupplementaryInsurance_DrugCondition] WITH CHECK
    ADD CONSTRAINT [FK_SupplementaryInsurance_DrugCondition_SupplementaryInsurance]
        FOREIGN KEY ([GoodsCode])
        REFERENCES [dbo].[KalaId] ([K_Code]) ON UPDATE CASCADE ON DELETE CASCADE;


    ALTER TABLE [dbo].[SupplementaryInsurance_DrugCondition] CHECK CONSTRAINT [FK_SupplementaryInsurance_DrugCondition_SupplementaryInsurance];
END;


IF NOT EXISTS
(
    SELECT name
    FROM sysobjects
    WHERE name = 'FK_SupplementaryInsurance_Relation_SupplementaryInsurance'
)
BEGIN
    ALTER TABLE [dbo].[SupplementaryInsurance_Relation] WITH CHECK
    ADD CONSTRAINT [FK_SupplementaryInsurance_Relation_SupplementaryInsurance]
        FOREIGN KEY ([InsuranceCode])
        REFERENCES [dbo].[SupplementaryInsurance] ([Code]) ON DELETE CASCADE;


    ALTER TABLE [dbo].[SupplementaryInsurance_Relation] CHECK CONSTRAINT [FK_SupplementaryInsurance_Relation_SupplementaryInsurance];
END;

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

    ALTER TABLE [dbo].[SupplementaryInsurance_Relation] WITH CHECK
    ADD CONSTRAINT [FK_SupplementaryInsurance_Relation_SupplementaryInsurance_Formula]
        FOREIGN KEY ([FormulaId])
        REFERENCES [dbo].[SupplementaryInsurance_Formula] ([Id]) ON DELETE CASCADE;
    ALTER TABLE [dbo].[SupplementaryInsurance_Relation] CHECK CONSTRAINT [FK_SupplementaryInsurance_Relation_SupplementaryInsurance_Formula];
END;
