CREATE TABLE [dbo].[pol_policies]
(
[pol_policy_id] [int] NOT NULL,
[pol_client_id] [int] NOT NULL,
[pol_start_date] [date] NOT NULL,
[pol_last_policy_situation_id] [int] NULL,
[pol_situations_count] [smallint] NULL,
[pol_age] [smallint] NULL CONSTRAINT [DF_pol_policies_pol_age] DEFAULT ((0)),
[pol_type_code__cts] [dbo].[ais_code_short] NULL,
[pol_branch_id] [int] NOT NULL,
[pol_department_code] [dbo].[ais_code_medium] NOT NULL,
[pol_company_id] [int] NOT NULL,
[pol_product_code] [dbo].[ais_code_short] NOT NULL,
[pol_currency_code] [dbo].[ais_code_short] NOT NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[pol_policies] ADD
CONSTRAINT [FK_pol_policies_act_cies] FOREIGN KEY ([pol_company_id]) REFERENCES [dbo].[act_cies] ([cie_actor_id])
ALTER TABLE [dbo].[pol_policies] ADD
CONSTRAINT [FK_pol_policies_pr_products_branches] FOREIGN KEY ([pol_product_code], [pol_branch_id]) REFERENCES [dbo].[pr_products_branches] ([prdb_product_code], [prdb_branch_id])
ALTER TABLE [dbo].[pol_policies] ADD
CONSTRAINT [FK_pol_policies_acc_currencies] FOREIGN KEY ([pol_currency_code]) REFERENCES [dbo].[acc_currencies] ([cur_currency_code])
ALTER TABLE [dbo].[pol_policies] ADD 
CONSTRAINT [PK_pol_policies] PRIMARY KEY CLUSTERED  ([pol_policy_id]) ON [PRIMARY]
ALTER TABLE [dbo].[pol_policies] ADD
CONSTRAINT [FK_pol_policies_act_branches_departments] FOREIGN KEY ([pol_branch_id], [pol_department_code]) REFERENCES [dbo].[act_branches_departments] ([brdep_branch_id], [brdep_department_code])
ALTER TABLE [dbo].[pol_policies] ADD
CONSTRAINT [FK_pol_policies_acc_cts_types] FOREIGN KEY ([pol_type_code__cts]) REFERENCES [dbo].[acc_cts_types] ([ctstyp_type_code])

GO

ALTER TABLE [dbo].[pol_policies] ADD CONSTRAINT [FK_pol_policies_act_clients] FOREIGN KEY ([pol_client_id]) REFERENCES [dbo].[act_clients] ([cli_actor_id])
GO

ALTER TABLE [dbo].[pol_policies] ADD CONSTRAINT [FK_pol_policies_pol_policies_situations] FOREIGN KEY ([pol_last_policy_situation_id]) REFERENCES [dbo].[pol_policies_situations] ([pols_policy_situation_id])
GO
