Advertisement
Guest User

Untitled

a guest
May 27th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. -- tables
  2. -- Table: Appointment
  3. CREATE TABLE Appointment (
  4. Appointment_Id Integer NOT NULL,
  5. Department_name varchar2(50) NOT NULL,
  6. Patient_complaint varchar2(15) NOT NULL,
  7. CONSTRAINT Appointment_pk PRIMARY KEY (Appointment_Id)
  8. ) ;
  9. insert into Appointment(Appointment_id, Department_name, Patient_complaint) values(1, 'otorhinolaryngology', 'Ear');
  10. insert into Appointment(Appointment_id, Department_name, Patient_complaint) values(2, 'otorhinolaryngology', 'Pest');
  11. insert into Appointment(Appointment_id, Department_name, Patient_complaint) values(3, 'otorhinolaryngology', 'Nose');
  12. insert into Appointment(Appointment_id, Department_name, Patient_complaint) values(4, 'dietitian', 'Over-weight');
  13.  
  14. select Department_name, Patient_complaint from Appointment;
  15.  
  16. -- Table: Doctor
  17. CREATE TABLE Doctor (
  18. Doctor_Id integer NOT NULL,
  19. eName varchar2(25) NOT NULL,
  20. Date_of_birth date NOT NULL,
  21. Profession varchar2(25) NOT NULL,
  22. Start_date_job date NOT NULL,
  23. Appointment_Appointment_Id Integer NULL,
  24. CONSTRAINT Doctor_pk PRIMARY KEY (Doctor_Id)
  25. ) ;
  26.  
  27. insert into Doctor(Doctor_Id, eName, Date_of_birth, Profession, Start_date_job)values(1, 'Jones',DATE '1975-03-06', 'otorhinolaryngology', DATE '2010-06-10');
  28. insert into Doctor(Doctor_Id, eName, Date_of_birth, Profession, Start_date_job)values(2, 'Michal',DATE '1979-03-05', 'dietitian', DATE '2017-05-07');
  29. insert into Doctor(Doctor_Id, eName, Date_of_birth, Profession, Start_date_job)values(3, 'Anna',DATE '1985-07-09', 'Surgeon', DATE '2000-05-10');
  30. insert into Doctor(Doctor_Id, eName, Date_of_birth, Profession, Start_date_job)values(4, 'Oliver',DATE '1982-03-05', 'esthesitc', DATE '2012-10-01');
  31.  
  32. select eName, Date_of_birth,Profession from Doctor;
  33.  
  34.  
  35. -- Table: Hospital
  36. CREATE TABLE Hospital (
  37. Hospital_Id integer NOT NULL,
  38. Name_Hos varchar2(50) NOT NULL,
  39. Address varchar2(50) NOT NULL,
  40. Phone integer NOT NULL,
  41. Fax integer NOT NULL,
  42. Email varchar2(50) NOT NULL,
  43. Standart_room_number integer NOT NULL,
  44. Private_room_number integer NOT NULL,
  45. Visit_Visit_Id integer NULL,
  46. CONSTRAINT Hospital_pk PRIMARY KEY (Hospital_Id)
  47. ) ;
  48.  
  49. insert into Hospital (Hospital_Id, Name_Hos, Address, Phone, Fax, Email, Standart_room_number, Private_room_number) values (1, 'Gazi Hospital', 'xxxAddresxxx', 123123123, 123123, 'sdadada@gmail.com', 60,40);
  50. insert into Hospital (Hospital_Id, Name_Hos, Address, Phone, Fax, Email, Standart_room_number, Private_room_number) values (2, 'Hacettepe Hospital', 'xxxAddressxx', 123123123, 112123, 'sdadada@gmail.com', 70,50);
  51. insert into Hospital (Hospital_Id, Name_Hos, Address, Phone, Fax, Email, Standart_room_number, Private_room_number) values (3, 'Ankara university hospital','xxxAddressxx', 123123123, 122313, 'sdadada@gmail.com', 50,30);
  52.  
  53. select Name_Hos, Address, Phone, Fax from Hospital;
  54.  
  55. -- Table: Patient
  56. CREATE TABLE Patient (
  57. Patient_Id integer NOT NULL,
  58. eName varchar2(25) NOT NULL,
  59. Surname varchar2(25) NOT NULL,
  60. Date_of_birth date NOT NULL,
  61. Gender varchar2(25) NOT NULL,
  62. Visit_Visit_Id integer NULL,
  63. CONSTRAINT Patient_pk PRIMARY KEY (Patient_Id)
  64. ) ;
  65.  
  66. insert into Patient (Patient_Id, eName, Surname, Date_of_birth, Gender)values (1,'Clark', 'Monasz', DATE '2018-05-10','Women');
  67. insert into Patient (Patient_Id, eName, Surname, Date_of_birth, Gender)values (2,'Liam', 'Taylor', DATE '2018-05-10','Man');
  68. insert into Patient (Patient_Id, eName, Surname, Date_of_birth, Gender)values (3,'Lewis', 'Ewans', DATE '2018-05-10','Man');
  69. insert into Patient (Patient_Id, eName, Surname, Date_of_birth, Gender)values (4,'Lee', 'Wilson', DATE '2018-05-10','Man');
  70.  
  71. select eName, Date_of_birth, Gender from Patient;
  72.  
  73.  
  74. -- Table: Patient_move_information
  75. CREATE TABLE Patient_move_information (
  76. Patient_move_information_Id integer NOT NULL,
  77. Made_operation varchar2(25) NOT NULL,
  78. Patient_Patient_Id integer NULL,
  79. CONSTRAINT Patient_move_information_pk PRIMARY KEY (Patient_move_information_Id)
  80. ) ;
  81.  
  82. insert into Patient_move_information(Patient_move_information_Id, Made_operation) values(1, 'Test');
  83. insert into Patient_move_information(Patient_move_information_Id, Made_operation) values(2, 'Surgery');
  84. insert into Patient_move_information(Patient_move_information_Id, Made_operation) values(3, 'Take blood');
  85.  
  86. select Made_operation from Patient_move_information;
  87.  
  88.  
  89. -- Table: Room_information
  90. CREATE TABLE Room_information (
  91. Room_information_Id integer NOT NULL,
  92. Bed_number integer NOT NULL,
  93. Private_room varchar2(25) NOT NULL,
  94. Standart_room varchar2(25) NOT NULL,
  95. Price integer NOT NULL,
  96. Patient_move_info_Id integer NULL,
  97. CONSTRAINT Room_information_pk PRIMARY KEY (Room_information_Id)
  98. ) ;
  99.  
  100. insert into Room_Information(Room_information_Id, Bed_number, Private_room, Standart_room, Price) values(1, 2, 'No', 'Yes', 500);
  101. insert into Room_Information(Room_information_Id, Bed_number, Private_room, Standart_room, Price) values(2, 1, 'Yes', 'No', 1000);
  102. insert into Room_Information(Room_information_Id, Bed_number, Private_room, Standart_room, Price) values(3, 2, 'No', 'Yes', 700);
  103.  
  104. select Bed_number, Private_room, Standart_room, Price from Room_Information;
  105.  
  106. select Bed_number, Private_room, Standart_room, Price from Room_Information;
  107. --when you want see max value from patient you have to use select max
  108. Select max(price) from Room_Information;
  109. --when you want see mix value from patient you have to use select min
  110. Select min(price) from Room_Information;
  111.  
  112. -- Table: Visit
  113. CREATE TABLE Visit (
  114. Visit_Id integer NOT NULL,
  115. Which_hospital varchar2(50) NOT NULL,
  116. Date_of_appointment date NOT NULL,
  117. Appointment_Appointment_Id Integer NULL,
  118. Patient_move_info_Id integer NULL,
  119. CONSTRAINT Visit_pk PRIMARY KEY (Visit_Id)
  120. ) ;
  121. insert into Visit(Visit_Id, Which_hospital, Date_of_appointment) values(1, 'Gazi Hospital',DATE '2019-10-06');
  122. insert into Visit(Visit_Id, Which_hospital, Date_of_appointment) values(2, 'Hacettepe Hospital',DATE '2019-07-20');
  123. insert into Visit(Visit_Id, Which_hospital, Date_of_appointment) values(3, 'Ankara University Hospital',DATE '2019-11-12');
  124.  
  125. Select Which_hospital, Date_of_appointment from Visit;
  126.  
  127. -- foreign keys
  128. -- Reference: Doctor_Appointment (table: Doctor)
  129. ALTER TABLE Doctor ADD CONSTRAINT Doctor_Appointment
  130. FOREIGN KEY (Appointment_Appointment_Id)
  131. REFERENCES Appointment (Appointment_Id);
  132.  
  133. -- Reference: Hospital_Visit (table: Hospital)
  134. ALTER TABLE Hospital ADD CONSTRAINT Hospital_Visit
  135. FOREIGN KEY (Visit_Visit_Id)
  136. REFERENCES Visit (Visit_Id);
  137.  
  138. -- Reference: Patient_Visit (table: Patient)
  139. ALTER TABLE Patient ADD CONSTRAINT Patient_Visit
  140. FOREIGN KEY (Visit_Visit_Id)
  141. REFERENCES Visit (Visit_Id);
  142.  
  143. -- Reference: Patient_move_info_Patient (table: Patient_move_information)
  144. ALTER TABLE Patient_move_information ADD CONSTRAINT Patient_move_info_Patient
  145. FOREIGN KEY (Patient_Patient_Id)
  146. REFERENCES Patient (Patient_Id);
  147.  
  148. -- Reference: Room_info_Patient_move_info (table: Room_information)
  149. ALTER TABLE Room_information ADD CONSTRAINT Room_info_Patient_move_info
  150. FOREIGN KEY (Patient_move_info_Id)
  151. REFERENCES Patient_move_information (Patient_move_information_Id);
  152.  
  153. -- Reference: Visit_Appointment (table: Visit)
  154. ALTER TABLE Visit ADD CONSTRAINT Visit_Appointment
  155. FOREIGN KEY (Appointment_Appointment_Id)
  156. REFERENCES Appointment (Appointment_Id);
  157.  
  158. -- Reference: Visit_Patient_move_information (table: Visit)
  159. ALTER TABLE Visit ADD CONSTRAINT Visit_Patient_move_information
  160. FOREIGN KEY (Patient_move_info_Id)
  161. REFERENCES Patient_move_information (Patient_move_information_Id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement