if not Exists(SELECT * FROM information_schema.tables where Table_name = 'Sanad') begin create table Sanad ( ID int primary key, Code int not null, FC_ID int references Finance_Cycle not null default -1, Pro_ID_VahedMali int references OtherProperties not null default -1, Tarikh int not null, Saat int not null Default 0, Sharh nvarchar(1000), Dom_ID_Noe int references Domain (ID) not null, --0 normal, 1 eftetahie, 2 ekhtetamie, 3 subsystem CodeKarbar int foreign key references karbar(code) not null, TarikhSabt int, SaatSabt smallint, Dom_ID_Vaziat int references Domain (ID) not null, --0 normal, 1 deleted, 2 sabte avvalie, 3 sabte ghatii,... Dom_ID_Marja int references Domain (ID)not null --0 factor, 1 daryaft, 2 pardakht, 3 bargasht az foroosh, 4 havaleh hesabdari,... ) end go if not Exists(SELECT * FROM information_schema.tables where Table_name = 'SanadDetail') begin --------------------------------جزئیات سند حسابداری create table SanadDetail ( ID int primary key identity(1,1), San_ID int foreign key references sanad(ID) not null, Radif int not null default 0, Kol_ID bigint foreign key references kol(code), Moin_ID bigint foreign key references moin(code), Taf_ID bigint foreign key references tafsili(code), Taf2_ID bigint foreign key references tafsili(code), Taf3_ID bigint foreign key references tafsili(code), Sharh nvarchar(3700), Bedehkar decimal(19,4) not null default 0, Bestankar decimal(19,4) not null default 0, Refrence_ID bigint not null default 0, Dom_ID_Marja smallint not null default 0 ) end go if not Exists(SELECT * FROM information_schema.tables where Table_name = 'SanadRefrenceID') begin create table SanadRefrenceID ( ID int primary key identity(1,1), San_ID int foreign key references Sanad(ID)not null, Bar_ID int foreign key references Bargeh(code), DaryaftPardakht_ID int foreign key references DaryaftPardakht(code), GardesheChek_ID int foreign key references GardesheChek(code), AnbarGardani_ID int foreign key references AnbarGardani(code), Prod_ID int references Product(ID) , KalDarAnbar_ID int references KalaDarAnbar(Code), Kal_ID int references Kala(Code), Taf_ID bigint references tafsili(Code) ) end