alter table tAccount drop constraint fk_tAcc_Type; alter table tAccountHistory drop constraint fk_tAccHistory_Acc; alter table tAccountHistory drop constraint fk_tAccHistory_Entry; alter table tBalance drop constraint fk_tBalance_Acc_dest; alter table tBalance drop constraint fk_tBalance_Acc_src; alter table tBalance drop constraint fk_tBalance_EntryType; alter table tRefAccount drop constraint fk_tRefAcc_CurCode; alter table tRefEntryAccount drop constraint fk_tRefEntryAcc_Acc_dest; alter table tRefEntryAccount drop constraint fk_tRefEntryAcc_Acc_src; alter table tRefEntryAccount drop constraint fk_tRefEntryAcc_Entry; drop table tAccount cascade constraints; drop table tAccountHistory cascade constraints; drop table tBalance cascade constraints; drop table tRefAccount cascade constraints; drop table tRefCurrency cascade constraints; drop table tRefEntry cascade constraints; drop table tRefEntryAccount cascade constraints; /*==============================================================*/ /* Table: tAccount */ /*==============================================================*/ create table tAccount ( AccountNo NUMBER not null, AccountType NUMBER not null, AccountName VARCHAR2(50) not null, constraint PK_TACCOUNT primary key (AccountNo) ); comment on table tAccount is 'Счета'; create index itAccountType on tAccount(AccountType); /*==============================================================*/ /* Table: tAccountHistory */ /*==============================================================*/ create table tAccountHistory ( RecNo NUMBER not null, AccountNo NUMBER not null, Remains NUMBER not null, constraint PK_TACCOUNTHISTORY primary key (RecNo, AccountNo) ); comment on table tAccountHistory is 'История изменения счета'; create index itAccHistoryRecNo on tAccountHistory(RecNo); create index itAccHistoryAccNo on tAccountHistory(AccountNo); /*==============================================================*/ /* Table: tBalance */ /*==============================================================*/ create table tBalance ( RecNo NUMBER not null, RecDate NUMBER not null, EntryType NUMBER not null, RecContent NUMBER not null, AccountNoSrc NUMBER not null, AccountNoDest NUMBER not null, Amount NUMBER not null, constraint PK_TBALANCE primary key (RecNo) ); comment on table tBalance is 'Баланс'; create index itBalanceEntry on tBalance(EntryType); create index itBalanceAccNoSrc on tBalance(AccountNoSrc); create index itBalanceAccNoDest on tBalance(AccountNoDest); /*==============================================================*/ /* Table: tRefAccount */ /*==============================================================*/ create table tRefAccount ( AccountType NUMBER not null, CurrencyCode NUMBER not null, AccountTypeName VARCHAR2(50) not null, AccountTypeCashFlag NUMBER(1) not null, AccountTypeMyFlag NUMBER(1) not null, constraint PK_TREFACCOUNT primary key (AccountType) ); comment on table tRefAccount is 'Справочник счетов'; create index itRefAccountCurrCode on tRefAccount(CurrencyCode); /*==============================================================*/ /* Table: tRefCurrency */ /*==============================================================*/ create table tRefCurrency ( CurrencyCode NUMBER not null, CurrencyCodeName VARCHAR2(50) not null, CurrencyCodeShortName VARCHAR2(3) not null, constraint PK_TREFCURRENCY primary key (CurrencyCode) ); comment on table tRefCurrency is 'Справочник валют'; /*==============================================================*/ /* Table: tRefEntry */ /*==============================================================*/ create table tRefEntry ( EntryType NUMBER not null, EntryTypeName VARCHAR2(50) not null, EntryTypeParent NUMBER, EntryOrderNo NUMBER, constraint PK_TREFENTRY primary key (EntryType) ); comment on table tRefEntry is 'Справочник статей'; alter table tRefEntry add constraint fk_tEntry_EntryTypeParent foreign key (EntryTypeParent) references tRefEntry (EntryType); /*==============================================================*/ /* Table: tRefEntryAccount */ /*==============================================================*/ create table tRefEntryAccount ( EntryType NUMBER not null, AccountNo_Src NUMBER not null, AccountNo_Dest NUMBER not null, AmountRule VARCHAR2(4000), constraint PK_TREFENTRYACCOUNT primary key (EntryType, AccountNo_Src, AccountNo_Dest) ); comment on table tRefEntryAccount is 'Справочник возможных счетов статьи'; create index itRefEntryAccEntry on tRefEntryAccount(EntryType); create index itRefEntryAccAccNoSrc on tRefEntryAccount(AccountNo_Src); create index itRefEntryAccAccNoDest on tRefEntryAccount(AccountNo_Dest); alter table tAccount add constraint fk_tAcc_Type foreign key (AccountType) references tRefAccount (AccountType); alter table tAccountHistory add constraint fk_tAccHistory_Acc foreign key (AccountNo) references tAccount (AccountNo); alter table tAccountHistory add constraint fk_tAccHistory_Entry foreign key (RecNo) references tBalance (RecNo); alter table tBalance add constraint fk_tBalance_Acc_dest foreign key (AccountNoDest) references tAccount (AccountNo); alter table tBalance add constraint fk_tBalance_Acc_src foreign key (AccountNoSrc) references tAccount (AccountNo); alter table tBalance add constraint fk_tBalance_EntryType foreign key (EntryType) references tRefEntry (EntryType); alter table tRefAccount add constraint fk_tRefAcc_CurCode foreign key (CurrencyCode) references tRefCurrency (CurrencyCode); alter table tRefEntryAccount add constraint fk_tRefEntryAcc_Acc_dest foreign key (AccountNo_Dest) references tAccount (AccountNo); alter table tRefEntryAccount add constraint fk_tRefEntryAcc_Acc_src foreign key (AccountNo_Src) references tAccount (AccountNo); alter table tRefEntryAccount add constraint fk_tRefEntryAcc_Entry foreign key (EntryType) references tRefEntry (EntryType);