Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /*CREATE TABLE Doctor(
  2. id BIGINT IDENTITY(1,1) NOT NULL,
  3. fio nVARCHAR(255) NOT NULL,
  4. department nVARCHAR(255),
  5. constraint pk_doctor PRIMARY KEY(id));
  6. CREATE TABLE Patient(
  7. id BIGINT IDENTITY(1,1) NOT NULL,
  8. fio nVARCHAR(255) NOT NULL,
  9. sex CHAR(7) null,
  10. birth_dt DATE NULL,
  11. constraint pk_patient PRIMARY KEY(id),
  12. check (sex='мужской' or sex='женский'));
  13. create table Diagnosis(
  14. id bigint identity(1,1) not null,
  15. name nvarchar(255) not null,
  16. code char(7),
  17. constraint code_length check (len(code) between 4 and 7),
  18. constraint pk_diagnosis primary key(id)
  19. );
  20. create table Case1(
  21. patient_id bigint not null,
  22. main_diag_id bigint not null,
  23. start_dt datetime null,
  24. end_dt datetime default getDate(),
  25. class_val int,
  26. constraint start_dt_check check(start_dt<=getDate()),
  27. constraint class_val_check check(class_val between 1 and 3),
  28. constraint patient_diag_pk primary key(patient_id,main_diag_id),
  29. constraint fk_patient foreign key(patient_id)
  30. references Patient(id),
  31. constraint fk_diag foreign key(main_diag_id)
  32. references Diagnosis(id));
  33. create table Step(
  34. patient_id bigint not null,
  35. main_diag_id bigint not null,
  36. diagnosis_id bigint not null,
  37. doctor_id bigint not null,
  38. days_off int,
  39. constraint days_check check(days_off>0),
  40. constraint patient_diag_doctor_pk primary key(patient_id,main_diag_id,doctor_id),
  41. constraint patient_fk foreign key (patient_id)
  42. references Patient(id),
  43. constraint main_diag_fk foreign key (main_diag_id)
  44. references Diagnosis(id),
  45. constraint diagnosis_fk foreign key(diagnosis_id)
  46. references Diagnosis(id));
  47.  
  48. 1е задание:
  49. alter table Doctor add nauchnaya_stepen varchar(30),
  50. constraint stepen_check check (nauchnaya_stepen='специалист 1й степени' or nauchnaya_stepen='кандидат наук' or nauchnaya_stepen='специалист 2й степени');
  51.  
  52. 2е задание:
  53. alter table Case1 drop constraint start_dt_check;
  54. alter table Case1 add constraint start_dt_check2 check(start_dt between '01.01.2014' and '01.12.2014' and end_dt<'31.12.2014');
  55.  
  56. 3е задание:*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement