Script.sql 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. create table "Roles"(
  2. RoleID int not null generated always as identity primary key,
  3. Title varchar(30) not null
  4. );
  5. create table "Trade networks"(
  6. TradeID int not null generated always as identity primary key,
  7. Title varchar(30) not null
  8. );
  9. create table "Acceptance"(
  10. AcceptanceID int not null generated always as identity primary key,
  11. Title varchar(30) not null
  12. );
  13. create table "Employees"(
  14. EmployeesID int not null generated always as identity primary key,
  15. Surname varchar(30) not null,
  16. "name" varchar(30) not null,
  17. Patronymic varchar(30) not null,
  18. PhoneNumber varchar(30) not null,
  19. Email varchar(30) not null,
  20. "role" int not null,
  21. "password" varchar(30) not null
  22. );
  23. create table "Outlets"(
  24. OutletID int not null generated always as identity primary key,
  25. Address varchar(100) not null,
  26. "location" varchar(100) not null,
  27. "Trade networks" int not null
  28. );
  29. create table "Projects"(
  30. ProjectID int not null generated always as identity primary key,
  31. Title varchar(30) not null,
  32. NumOfVisitsPerWeek int not null
  33. );
  34. create table "Products"(
  35. ProductID int not null generated always as identity primary key,
  36. Title varchar(30) not null,
  37. Project int not null
  38. );
  39. create table "Visits"(
  40. VisitID int not null generated always as identity primary key,
  41. Outlet int not null,
  42. Project int not null,
  43. VisitDate date not null,
  44. VisitTime time not null,
  45. Accepted int not null,
  46. MerchComment varchar(200) not null
  47. );
  48. create table "Product reports"(
  49. ProductReportID int not null generated always as identity primary key,
  50. Product int not null,
  51. Price int not null,
  52. PriceToTheCard int not null,
  53. ActualBalance int not null,
  54. VirtualBalance int not null,
  55. Visit int not null
  56. );
  57. create table "Projects and outlets"(
  58. ProjectID int not null,
  59. OutletID int not null
  60. );
  61. create table "Projects and employees"(
  62. EmployeeID int not null,
  63. OutletID int not null
  64. );
  65. alter table "Employees"
  66. add foreign key (Role) references "Roles"(roleiD)
  67. alter table "Outlets"
  68. add foreign key ("Trade networks") references "Trade networks"(tradeiD)
  69. alter table "Visits"
  70. add foreign key (accepted) references "Acceptance"(acceptanceid)
  71. alter table "Products"
  72. add foreign key (project) references "Projects"(projectid)
  73. alter table "Product reports"
  74. add foreign key (product) references "Products"(productid)
  75. alter table "Product reports"
  76. add foreign key (visit) references "Visits"(visitid)
  77. alter table "Projects and outlets"
  78. add foreign key (projectid) references "Projects"(projectid)
  79. alter table "Projects and outlets"
  80. add foreign key (outletid) references "Outlets"(outletid)
  81. alter table "Projects and employees"
  82. rename column outletid to projectid
  83. alter table "Projects and employees"
  84. add foreign key (projectid) references "Projects"(projectid)
  85. alter table "Projects and employees"
  86. add foreign key (employeeid) references "Employees"(employeesid)
  87. alter table "Visits"
  88. add foreign key (project) references "Projects"(projectid)
  89. alter table "Visits"
  90. add foreign key (outlet) references "Outlets"(outletid)