CREATE TABLE [dbo].[acc_accounts]
(
[a_account_id] [int] NOT NULL,
[a_type_code] [dbo].[ais_code_short] NOT NULL,
[a_branch_id] [int] NOT NULL,
[a_amount] [dbo].[ais_decimal2] NULL,
[a_operation_utc_date] [datetime] NOT NULL,
[a_lettering] [int] NULL,
[a_currency_code] [dbo].[ais_code_short] NOT NULL,
[a_actor_id] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [CK_acc_accounts__a_lettering] CHECK ((isnull([a_lettering],(0))>(0) AND ([a_type_code]='T' OR [a_type_code]='R') OR NOT ([a_type_code]='T' OR [a_type_code]='R')))
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [PK_acc_accounts] PRIMARY KEY CLUSTERED  ([a_account_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [FK_acc_accounts_act_actors] FOREIGN KEY ([a_actor_id]) REFERENCES [dbo].[act_actors] ([act_actor_id])
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [FK_acc_accounts_act_branches] FOREIGN KEY ([a_branch_id]) REFERENCES [dbo].[act_branches] ([br_actor_id])
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [FK_acc_accounts_acc_currencies] FOREIGN KEY ([a_currency_code]) REFERENCES [dbo].[acc_currencies] ([cur_currency_code])
GO
ALTER TABLE [dbo].[acc_accounts] ADD CONSTRAINT [FK_acc_accounts_acc_accounts_types] FOREIGN KEY ([a_type_code]) REFERENCES [dbo].[acc_accounts_types] ([atyp_type_code])
GO
