-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab5.sql
93 lines (74 loc) · 2.94 KB
/
lab5.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
CREATE DATABASE LAB5;
USE LAB;
CREATE TABLE Clients(
ClientID INT,
ClientName VARCHAR(50) NOT NULL,
Address VARCHAR(100),
Email VARCHAR(30) UNIQUE,
Phone INT,
Business VARCHAR(30) NOT NULL, --Business type of client like Manufacturer, Reseller ...
PRIMARY KEY (ClientID)
)
CREATE TABLE Projects(
ProjectID INT,
Description VARCHAR(100), --Description of project like Accounting, Payroll, ...
StartDate DATE, --Start date of project
PlannedEndDate DATE, --Planned end date of project
ActualEndDate DATE ,
Budget INT CHECK(Budget > 0),
ClientID INT,
CHECK(ActualEndDate > PlannedEndDate),
FOREIGN KEY (ClientID) REFERENCES Clients(ClientID)
)
CREATE TABLE Departments(
DepartmentNo INT,
DepartmentName VARCHAR(100) NOT NULL,
PRIMARY KEY (DepartmentNo)
)
CREATE TABLE Employees(
EmployeeNo INT,
EmplouyeeName VARCHAR(20) NOT NULL,
Job VARCHAR(20),
Salary INT CHECK(Salary > 1700),
DepartmentNo INT, --DepartmentNo as per departments table
PRIMARY KEY (EmployeeNo),
FOREIGN KEY (DepartmentNo) REFERENCES Departments(DepartmentNo)
)
CREATE TABLE EmployeeProjectTasks(
ProjectID INT,
EmployeeNo INT,
StartDate DATE, --Start date when employee begins task on this project
EndDate DATE, --End date when employee finishes task on this project
Task VARCHAR(30), --Task performed by employee like designing, coding ..
Status VARCHAR(30), -- Status of task like ‘in progress’, ‘complete’,‘cancelled’
PRIMARY KEY (ProjectID, EmployeeNo),
FOREIGN KEY (ProjectID) REFERENCES Projects(ProjectID),
FOREIGN KEY (EmployeeNo) REFERENCES Employees(EmployeeNo)
)
INSERT INTO Clients(ClientID, ClientName, Address, Email, Phone, Business)
VALUES
(1, 'Nayem', 'Portugal', 'shnartho@yahoo.com', 920485163, 'MoslinMeta'),
(2, 'Belmahi', 'Morrocco', 'belmahi@yahoo.com', 920485162, 'BelmahiMeta');
INSERT INTO Projects(ProjectID, Description, StartDate, PlannedEndDate, ActualEndDate, Budget, ClientID)
VALUES
(1, 'Accounting', 12/7/2021, 16/7/2021, 18/7/2021, 2500, 1),
(2, 'Payroll', 12/7/2021, 16/7/2021, 18/7/2021, 2502, 2);
INSERT INTO Departments(DepartmentNo, DepartmentName)
VALUES
(1, 'Main Department'),
(2, 'Secondary Department');
INSERT INTO Employees(EmployeeNo, EmployeeName, Job, Salary, DepartmentNo)
VALUES
(1, 'Nayem Pagla', 'Caretaker', 2500, 1);
(2, 'Maheera', 'Doctor', 4000, 2);
INSERT INTO EmployeeProjectTasks(ProjectID, EmployeeNo, StartDate, EndDate, Task, Status)
VALUES
(1, 1, 22/7/2021, 28/7/2021, 'Data Entry', 'in progress'),
(2, 2, 22/7/2021, 29/7/2021, 'Sergery', 'Complete');
select * FROM Employees where EmployeeName like 'M%';
select EmployeeNo, EmployeeName
from table Employees
order by len(EmployeeName) desc;
select Departments.DepartmentName, Employees.EmployeeName, Employees.Salary
from LAB5
order by Salary desc;