Новый скрипт бд.sql 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --drop table MedicalHistory;
  2. --drop table Animals;
  3. --drop table Doctors;
  4. --drop table Services;
  5. --drop table Owners;
  6. --drop table Users;
  7. create table Users
  8. (user_id serial not null constraint pk_user primary key,
  9. Surname varchar(100) not null,
  10. Name varchar(100) not null,
  11. Phone varchar(20) not null constraint un_user_phone unique,
  12. Email varchar(500) not null constraint un_user_email unique,
  13. Password varchar(500) not null);
  14. create table Doctors
  15. (doctor_id serial not null constraint pk_doctor primary key,
  16. Surname varchar(100) not null,
  17. Name varchar(100) not null,
  18. HireDate date not null,
  19. Profession varchar(150) not null,
  20. Honors text);
  21. create table Services
  22. (service_id serial not null constraint pk_service primary key,
  23. Title varchar(100) not null,
  24. Description text not null,
  25. Price double precision not null);
  26. create table ServiceDoctor
  27. (service_id int not null,
  28. doctor_id int not null,
  29. constraint fk_service_to_servicedoctor foreign key (service_id)
  30. references Services(service_id) on delete cascade,
  31. constraint fk_doctor_to_servicedoctor foreign key (doctor_id)
  32. references Doctors(doctor_id) on delete cascade)
  33. create table Animals
  34. (animal_id serial not null constraint pk_animal primary key,
  35. Name varchar(100) not null,
  36. Age int not null,
  37. Breed varchar(100) not null constraint df_animal_breed default 'Отстутсвует',
  38. Weight int not null,
  39. Description text,
  40. Owner int,
  41. Image text,
  42. constraint fk_owner_to_animal foreign key (Owner)
  43. references Users(user_id) on delete cascade);
  44. create table MedicalHistory
  45. (kard_id serial not null constraint pk_kard primary key,
  46. Animal int not null,
  47. VisitingTime timestamp not null,
  48. Doctor int not null,
  49. Service int not null,
  50. constraint fk_animal_to_kard foreign key (Animal)
  51. references Animals(animal_id) on delete cascade,
  52. constraint fk_doctor_to_kard foreign key (Doctor)
  53. references Doctors(doctor_id) on delete cascade,
  54. constraint fk_service_to_kard foreign key (Service)
  55. references Services(service_id) on delete cascade);