CREATE TABLE [dbo].[pol_policies_situations_repartitions]
(
[polsr_policy_situation_id] [int] NOT NULL,
[polsr_company_id] [int] NOT NULL,
[polsr_leader] [bit] NOT NULL,
[polsr_premium_part] [dbo].[ais_decimal4] NULL,
[polsr_commission_part] [dbo].[ais_decimal4] NULL,
[polsr_frt_prc] [dbo].[ais_decimal4] NULL,
[polsr_frt] [dbo].[ais_decimal2] NULL,
[polsr_reptype_code] [dbo].[ais_code_short] NULL CONSTRAINT [DF_pol_policies_situations_repartitions_polsr_reptype_code_1] DEFAULT ('FI')
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_commission_part] CHECK (([polsr_commission_part] IS NULL OR [polsr_commission_part]>=(0) AND [polsr_commission_part]<=(100)))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_frt_leader] CHECK (([polsr_leader]<>(0) OR [polsr_frt] IS NULL))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_frt_prc_leader] CHECK (([polsr_leader]<>(0) OR [polsr_frt_prc] IS NULL))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_type_rep] CHECK (([polsr_leader]=(0) OR [polsr_reptype_code] IS NOT NULL))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_premium_part] CHECK (([polsr_premium_part] IS NULL OR [polsr_premium_part]>=(0) AND [polsr_premium_part]<=(100)))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [CK_pol_policies_situations_repartitions_frt] CHECK ((isnull([polsr_frt],(0))=(0) OR isnull([polsr_frt_prc],(0))=(0)))
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [PK_pol_policies_situations_repartitions] PRIMARY KEY CLUSTERED  ([polsr_policy_situation_id], [polsr_company_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [FK_pol_policies_situations_repartitions_act_cies] FOREIGN KEY ([polsr_company_id]) REFERENCES [dbo].[act_cies] ([cie_actor_id])
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [FK_pol_policies_situations_repartitions_nm_repartitions_types] FOREIGN KEY ([polsr_reptype_code]) REFERENCES [dbo].[nm_repartitions_types] ([nmrt_reptype_code])
GO
ALTER TABLE [dbo].[pol_policies_situations_repartitions] ADD CONSTRAINT [FK_pol_policies_situations_repartitions_pol_policies_situations] FOREIGN KEY ([polsr_policy_situation_id]) REFERENCES [dbo].[pol_policies_situations] ([pols_policy_situation_id])
GO
