if not Exists(SELECT * FROM information_schema.tables where Table_name = 'ControlStructure') begin Create table ControlStructure ( ID int primary key, Code int not null, Dom_ID int references Domain (ID) not null, Title nvarchar(200), Sharh nvarchar(500), InitializeGrid nvarchar(1000), ColumnCount smallint not null default 1, Query nvarchar(max), Pro_ID_Report int references OtherProperties (ID) null, TarikhSabt int not null, SaatSabt smallint not null, CodeKarbar int references karbar(ID) not null ) end if not Exists(SELECT * FROM information_schema.tables where Table_name = 'ControlStructureDetail') begin Create table ControlStructureDetail ( ID int primary key, CS_ID int references ControlStructure (ID) not null, Dom_ID_Control int references Domain (ID) not null, Dom_ID_Validation int references Domain (ID) not null, Dom_ID_Status int references Domain (ID) not null, Title nvarchar(200), Name nvarchar(200), InitializeValue nvarchar(500), DefaultValue nvarchar(1000), [Priority] smallint not null, Dom_ID_Dock int references Domain (ID) not null, Width int not null, Query nvarchar(max), ShowInList bit not null, ) end if not Exists(SELECT * FROM information_schema.tables where Table_name = 'Repair') begin Create table Repair ( ID int primary key, CS_ID int references ControlStructure (ID) not null, FC_ID int references Finance_Cycle(ID) not null, Org_ID int references OtherProperties(ID) not null, Mat_ID bigint references Matter(ID) not null, Dom_ID_Progress int references Domain(ID) not null, Code int not null, Tarikh int not null, Taf_ID bigint references Tafsili(ID) not null, Sharh nvarchar(1000), TarikhSabt int not null, SaatSabt smallint not null, CodeKarbar int references Karbar(ID) not null ) end if not Exists(SELECT * FROM information_schema.tables where Table_name = 'RepairProperty') begin Create table RepairProperty ( ID int primary key, Rep_ID int References Repair(ID) not null, CSD_ID int references ControlStructureDetail(ID) not null, Value nvarchar(500) ) end if not Exists(SELECT * FROM information_schema.tables where Table_name = 'RepairDetail') begin Create table RepairDetail ( ID int primary key, Rep_ID int References Repair(ID) not null, Dom_ID_Type int References Domain(ID) not null, Tarikh int not null, Saat smallint not null, [Percent] smallint not null, Sharh nvarchar(1000), Kal_ID int References Kala(ID) null, Tedad float, Mablagh decimal(19,4), TarikhSabt int not null, SaatSabt smallint not null, CodeKarbar int references Karbar(ID) not null ) end