fork download
  1. create database HospitalSystem;
  2. create table person(
  3. National_ID int PRIMARY key,
  4. FirstName varchar(50) check(FirstName like '^[A-Za-z]+$') not null,
  5. LastName varchar(50) check(LastName like '^[A-Za-z]+$') not null,
  6. BirthDate date not null,
  7. City varchar(50) not null,
  8. street varchar(50) not null,
  9. gender char check(gender in ('M','F')),
  10. state varchar(50) not null
  11. )
  12. create table Contact(
  13. National_ID int ,
  14. Contact varchar(15) check(Contact like '^[0-9]+$'),
  15. PRIMARY KEY (National_ID, Contact),
  16. FOREIGN KEY (National_ID) REFERENCES person(National_ID)
  17. )
  18. create table Email(
  19. National_ID int,
  20. email varchar(50) check(email like '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
  21. PRIMARY KEY (National_ID,email)
  22. FOREIGN KEY (National_ID) REFERENCES person(National_ID)
  23. )
  24. create table Employee(
  25. National_ID int ,
  26. Employee_ID int PRIMARY key,
  27. Salary money not null,
  28. Hire_Date date not null,
  29. Resign_Date date null,
  30. FOREIGN KEY (National_ID) REFERENCES person(National_ID)
  31. )
  32. create table Nurse(
  33. Nurse_ID int PRIMARY key,
  34. Employee_ID int,
  35. shift varchar(50),
  36. FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
  37. )
  38. create table Department(
  39. Department_Name varchar(50) PRIMARY key,
  40. Department_Floor int not null,
  41. Department_Building int not null
  42. )
  43. create table Nurse_Department(
  44. Nurse_ID int,
  45. Department_Name varchar(50),
  46. PRIMARY KEY (Nurse_ID,Department_Name),
  47. FOREIGN KEY (Nurse_ID) REFERENCES Nurse(Nurse_ID),
  48. FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name)
  49. )
  50. create table Doctor(
  51. Doctor_ID int PRIMARY KEY,
  52. Department_Name varchar(50),
  53. Employee_ID int,
  54. Year_Of_Experience int DEFAULT 0,
  55. FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
  56. FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
  57. )
  58. create table Doctor_Qualification(
  59. Doctor_ID int,
  60. Qualification varchar(50),
  61. PRIMARY KEY(Doctor_ID,Qualification),
  62. FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID)
  63. )
  64. create table NonScientific_Employee(
  65. NSE_ID INT PRIMARY KEY,
  66. NSE_ROLE varchar(50),
  67. Department_Name varchar(50),
  68. Employee_ID int,
  69. FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
  70. FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
  71. )
  72. create table Device(
  73. Device_ID int PRIMARY KEY,
  74. Device_Name varchar(50) not null,
  75. Device_Type varchar(50) not null
  76. )
  77. create table Room(
  78. Room_ID int PRIMARY KEY,
  79. Room_Type varchar(50) not null,
  80. Room_Capacity int not null,
  81. Department_Name varchar(50),
  82. Device_ID int,
  83. FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
  84. FOREIGN KEY (Device_ID) REFERENCES Device(Device_ID),
  85. )
  86. create table Nurse_AssignedRoom(
  87. Room_ID int,
  88. Nurse_ID int
  89. PRIMARY KEY(Room_ID,Nurse_ID),
  90. FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
  91. FOREIGN KEY (Nurse_ID) REFERENCES Nurse(Nurse_ID),
  92. )
  93. create table Patient(
  94. Patient_ID int PRIMARY KEY,
  95. Residency_Start_Date date not null,
  96. Residency_End_Date date null,
  97. Room_ID int,
  98. National_ID int,
  99. FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
  100. FOREIGN KEY (National_ID) REFERENCES person(National_ID)
  101. )
  102. create table Prescription(
  103. Prescription_ID int PRIMARY KEY,
  104. Prescription_Date date not null,
  105. Instructions varchar(50),
  106. Diagnosis_Code varchar(50) not null,
  107. Patient_ID int
  108. FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID)
  109. )
  110. create table Medicine(
  111. Medicine_ID int PRIMARY KEY,
  112. Medicine_Name varchar(50),
  113. Expiry_Date date
  114. )
  115. create table Prescription_Medicine(
  116. Prescription_ID int,
  117. Medicine_ID int,
  118. Quantity int not null,
  119. Dosage varchar(50) check(Dosage like '^\d+(\.\d+)?(mg|ml|g|L)$') not null,
  120. Frequency int not null,
  121. PRIMARY KEY(Prescription_ID,Medicine_ID),
  122. FOREIGN KEY (Prescription_ID) REFERENCES Prescription(Prescription_ID),
  123. FOREIGN KEY (Medicine_ID) REFERENCES Medicine(Medicine_ID)
  124. )
  125. create table Appointment(
  126. Appointment_ID int PRIMARY KEY,
  127. Appointment_Status varchar(50)
  128. check(Appointment_Status in('Pending','Confirme','Complete','Canceled','Reschedule','No Show')),
  129. Room_ID int,
  130. Appointment_Date datetime2 not null,
  131. Patient_ID int,
  132. Doctor_ID int ,
  133. FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID),
  134. FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
  135. FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID)
  136. )
  137. create table Bill(
  138. Appointment_ID int PRIMARY KEY,
  139. amount money not null,
  140. Tax money not null ,
  141. Discount decimal(4,2)
  142. FOREIGN KEY (Appointment_ID) REFERENCES Appointment(Appointment_ID)
  143. )
Success #stdin #stdout #stderr 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "database": syntax error
Error: near line 2: near "create": syntax error