IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'CoFamilyCode')
BEGIN
CREATE TABLE [dbo].[CoFamilyCode]
(
    [GoodsCode] [VARCHAR](15) NOT NULL,
    [InsuranceType] [SMALLINT] NOT NULL,
    [GenericCode] [VARCHAR](6) NOT NULL,
    [IRCCode] [VARCHAR](16) NULL,
    [CreatedOn] [DATETIME] NULL
        DEFAULT (GETDATE()),
    CONSTRAINT [PK_CoFamilyCode]
        PRIMARY KEY CLUSTERED (
                                  [GoodsCode] ASC,
                                  [InsuranceType] ASC,
                                  [GenericCode] ASC
                              )
) ON [PRIMARY];

ALTER TABLE [dbo].[CoFamilyCode] WITH CHECK
ADD CONSTRAINT [FK_CoFamilyCode_KalaId]
    FOREIGN KEY ([GoodsCode])
    REFERENCES [dbo].[KalaId] ([K_Code]) ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE [dbo].[CoFamilyCode] CHECK CONSTRAINT [FK_CoFamilyCode_KalaId];
END;