Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. BEGIN TRANSACTION;
  2.  
  3. CREATE TABLE Schedule (
  4. ScheduleID int AUTO_INCREMENT,
  5. Date varchar(255),
  6. PRIMARY KEY (ScheduleID)
  7. );
  8.  
  9. INSERT INTO Schedule (ScheduleID, Date)
  10. VALUES (1, "MONDAY");
  11.  
  12. INSERT INTO Schedule (ScheduleID, Date)
  13. VALUES (2, "MONDAY");
  14.  
  15. INSERT INTO Schedule (ScheduleID, Date)
  16. VALUES (3, "MONDAY");
  17.  
  18. INSERT INTO Schedule (Date)
  19. VALUES ("THURSDAY");
  20.  
  21. INSERT INTO Schedule (Date)
  22. VALUES ("FRIDAY");
  23.  
  24. INSERT INTO Schedule (Date)
  25. VALUES ("SATURDAY");
  26.  
  27. INSERT INTO Schedule (Date)
  28. VALUES ("SUNDAY");
  29.  
  30. CREATE TABLE ShiftInstance (
  31. ShiftInstanceID int AUTO_INCREMENT,
  32. ScheduleID int AUTO_INCREMENT,
  33. DeptID int AUTO_INCREMENT,
  34. NurseID int AUTO_INCREMENT,
  35. Date varchar(255),
  36. StartTime int,
  37. EndTime int,
  38. PRIMARY KEY (ShiftInstanceID),
  39. FOREIGN KEY (ScheduleID) REFERENCES Schedule(ScheduleID)
  40. );
  41.  
  42. INSERT INTO ShiftInstance (ShiftInstanceID, ScheduleID, DeptID, NurseID, Date, StartTime, EndTime)
  43. VALUES (1, 1, 1, 1, "9/21/2017", 7, 3);
  44.  
  45. INSERT INTO ShiftInstance (ShiftInstanceID, ScheduleID, DeptID, NurseID, Date, StartTime, EndTime)
  46. VALUES (2, 2, 2, 2, "9/21/2017", 3, 11);
  47.  
  48. INSERT INTO ShiftInstance (ShiftInstanceID, ScheduleID, DeptID, NurseID, Date, StartTime, EndTime)
  49. VALUES (3, 3, 3, 3, "9/21/2017", 3, 11);
  50.  
  51.  
  52. CREATE TABLE Department (
  53. DeptID int AUTO_INCREMENT,
  54. DeptName varchar(255),
  55. StaffSize int,
  56. PRIMARY KEY (DeptID)
  57. );
  58.  
  59. INSERT INTO Department(DeptID, DeptName, StaffSize)
  60. VALUES (1, "SURG", 25);
  61.  
  62. INSERT INTO Department(DeptID, DeptName, StaffSize)
  63. VALUES (2, "SURG", 25);
  64.  
  65. INSERT INTO Department(DeptID, DeptName, StaffSize)
  66. VALUES (3, "SURG", 25);
  67.  
  68. CREATE TABLE Nurses (
  69. NurseID int AUTO_INCREMENT,
  70. DeptID int AUTO_INCREMENT,
  71. FirstName varchar(255),
  72. LastName varchar(255),
  73. Title varchar(255),
  74. IsSalaried int,
  75. StartDate varchar(255),
  76. PRIMARY KEY (NurseID),
  77. FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
  78. );
  79.  
  80. INSERT INTO Nurses(NurseID, DeptID, FirstName, LastName, Title, IsSalaried, StartDate)
  81. VALUES (1, 1, "Adam", "Apple", "The Big Cheese", 0, "1/1/1970");
  82.  
  83. INSERT INTO Nurses(NurseID, DeptID, FirstName, LastName, Title, IsSalaried, StartDate)
  84. VALUES (2, 2, "Betty", "Boop", "The Bigg Cheese", 0, "1/1/1970");
  85.  
  86. INSERT INTO Nurses(NurseID, DeptID, FirstName, LastName, Title, IsSalaried, StartDate)
  87. VALUES (3, 3, "Charlie", "Chaplin", "The Biggg Cheese", 0, "1/1/1970");
  88.  
  89. INSERT INTO Nurses(NurseID, DeptID, FirstName, LastName, Title, IsSalaried, StartDate)
  90. VALUES (4, 4, "Debbit", "Donsht", "The Bigggg Cheese", 0, "1/1/1970");
  91.  
  92.  
  93. COMMIT;
  94.  
  95. /* Display all the records from the table */
  96. SELECT Nurses.FirstName, Nurses.LastName, Schedule.Date, ShiftInstance.StartTime, ShiftInstance.EndTime, Department.DeptName FROM Schedule, ShiftInstance, Department, Nurses
  97. WHERE Schedule.ScheduleID = ShiftInstance.ScheduleID
  98. AND ShiftInstance.DeptID = Department.DeptID
  99. AND ShiftInstance.NurseID = Nurses.NurseID
  100. ORDER BY Nurses.LastName;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement