RelationModel: create.sql

File create.sql, 2.1 KB (added by 151131, 2 days ago)
Line 
1DROP TABLE IF EXISTS Review;
2DROP TABLE IF EXISTS Examination;
3DROP TABLE IF EXISTS IsApprovedMedicineRecepit;
4DROP TABLE IF EXISTS MedicineRecepit;
5DROP TABLE IF EXISTS Report;
6DROP TABLE IF EXISTS Comment;
7DROP TABLE IF EXISTS Specialist;
8DROP TABLE IF EXISTS Doctor;
9DROP TABLE IF EXISTS Patient;
10DROP TABLE IF EXISTS AppUser;
11
12CREATE TABLE AppUser (
13 ssn VARCHAR(13) PRIMARY KEY,
14 email VARCHAR(100) NOT NULL,
15 password VARCHAR(100) NOT NULL,
16 firstName VARCHAR(100) NOT NULL,
17 lastName VARCHAR(100) NOT NULL
18);
19CREATE TABLE Patient (
20 userId VARCHAR(13) PRIMARY KEY REFERENCES AppUser(ssn),
21 patientId VARCHAR(13)
22);
23CREATE TABLE Doctor (
24 userId VARCHAR(13) PRIMARY KEY REFERENCES AppUser(ssn),
25 workingHours VARCHAR(50),
26 licenseNumber VARCHAR(50),
27 hospitalId VARCHAR(50)
28);
29CREATE TABLE Specialist (
30 userId VARCHAR(13) PRIMARY KEY REFERENCES AppUser(ssn),
31 licenseNumber VARCHAR(50),
32 hospitalId VARCHAR(50)
33);
34CREATE TABLE Comment (
35 commentId INT PRIMARY KEY,
36 createdBy VARCHAR(13) REFERENCES AppUser(ssn),
37 createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
38 comment VARCHAR(300)
39);
40CREATE TABLE Report (
41 reportId INT PRIMARY KEY,
42 description VARCHAR(300),
43 isFinished BOOLEAN
44);
45CREATE TABLE MedicineRecepit (
46 medicineRecepitId INT PRIMARY KEY,
47 reportId INT REFERENCES Report(reportId),
48 medicineName VARCHAR(50),
49 quantity INT
50);
51CREATE TABLE IsApprovedMedicineRecepit (
52 approvalId INT PRIMARY KEY,
53 receiptId INT REFERENCES MedicineRecepit(medicineRecepitId),
54 approvedBy VARCHAR(13) REFERENCES AppUser(ssn),
55 IsApproved BOOLEAN
56);
57CREATE TABLE Examination (
58 examinationId INT PRIMARY KEY,
59 patientId VARCHAR(13) REFERENCES AppUser(ssn),
60 doctorId VARCHAR(13) REFERENCES AppUser(ssn),
61 specialistId VARCHAR(13) REFERENCES AppUser(ssn),
62 dateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
63);
64CREATE TABLE Review (
65 reviewId INT PRIMARY KEY,
66 patientId VARCHAR(13) REFERENCES AppUser(ssn),
67 doctorId VARCHAR(13) REFERENCES AppUser(ssn),
68 rank INT CHECK (rank >= 1 AND rank <= 5)
69);