Advertisement
amltms

Untitled

Mar 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. CREATE TABLE Roles (
  2. RoleID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  3. RoleName varchar(255)
  4. );
  5.  
  6. CREATE TABLE Users (
  7. UserID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  8. FirstName varchar(255) NOT NULL,
  9. LastName varchar(255) NOT NULL,
  10. Password varchar(255) NOT NULL,
  11. PhoneNumber varchar(15),
  12. Email varchar(255) NOT NULL,
  13. Bio text,
  14. RoleID int NOT NULL,
  15. LecturerID int,
  16. Privacy int NOT NULL,
  17. FOREIGN KEY (RoleID) REFERENCES Roles(RoleID)
  18. );
  19.  
  20. ALTER TABLE Users ADD CONSTRAINT fk_lecturer
  21. FOREIGN KEY (LecturerID) REFERENCES Users(UserID);
  22.  
  23.  
  24. CREATE TABLE Messages (
  25. MessageID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  26. MessageTitle varchar(255),
  27. Message text NOT NULL,
  28. SenderID int NOT NULL,
  29. RecieverID int NOT NULL,
  30. MessageDate DATETIME NOT NULL,
  31. FOREIGN KEY (SenderID) REFERENCES Users(UserID),
  32. FOREIGN KEY (RecieverID) REFERENCES Users(UserID)
  33. );
  34.  
  35.  
  36.  
  37. CREATE TABLE Meetings (
  38. MeetingID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  39. Message varchar(255) NOT NULL,
  40. MeetingDate DATETIME NOT NULL,
  41. SenderID int NOT NULL,
  42. RecieverID int NOT NULL,
  43. FOREIGN KEY (SenderID) REFERENCES Users(UserID),
  44. FOREIGN KEY (RecieverID) REFERENCES Users(UserID)
  45. );
  46.  
  47. /*Insert Roles*/
  48. INSERT INTO Roles (RoleName) VALUES ("Student");
  49. INSERT INTO Roles (RoleName) VALUES ("Lecturer");
  50. INSERT INTO Roles (RoleName) VALUES ("Admin");
  51.  
  52.  
  53. INSERT INTO Users (FirstName,LastName,Password,PhoneNumber,Email,Bio,RoleID,Privacy) VALUES ("Admin");
  54.  
  55.  
  56.  
  57. DROP TABLE Meetings;
  58. DROP TABLE Messages;
  59. DROP TABLE Users;
  60. DROP TABLE Roles;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement