-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.sql
More file actions
110 lines (86 loc) · 2.39 KB
/
Copy pathtask.sql
File metadata and controls
110 lines (86 loc) · 2.39 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
create Database task
use task
--create Table:
create table Employee(
SSN int primary key identity(1, 1),
SuperID int,
FName nvarchar(10),
LName nvarchar(10),
BrithDate date,
Gender nvarchar(1)
foreign key (superID) references Employee(SSN)
);
ALTER TABLE Employee
add BrithDate date
drop table Employee
select * From Employee
create table Departement(
DNum int primary key,
DName nvarchar(10),
SSN int,
foreign key (SSN) references Employee(SSN),
HireDate date
);
create table Dept_Location(
DNum int,
DLocation nvarchar(20),
foreign key (DNum) references Departement(DNum),
primary key (DNum, DLocation)
);
create table Project(
PNum int primary key,
DNum int,
PName nvarchar(20),
City nvarchar(50),
PLocation nvarchar(100),
foreign key (DNum) references Departement(DNum)
);
create table EmployeeDependent(
SSN int,
DependentName nvarchar(20),
primary key (SSN, DependentName),
BirthDay date,
Gender bit default 0,
foreign key (SSN) references Employee(SSN)
);
create table My_work(
SSN int,
PNum int,
foreign key (SSN) references Employee(SSN),
foreign key (PNum) references Project(PNum),
Primary key (SSN, PNum),
M_hours int check (M_hours between 0 and 24)
);
--Insert into Employee
Insert into Employee (FName, LName, BrithDate, Gender)
values ('Nusiba', 'Alnabhani', '2000-08-14', 'F'),
('Hamza', 'Alsalmi', '1995-06-22', 'M'),
('Sara', 'Alshekeli', '2002-07-01', 'F');
UPDATE Employee
SET SuperID = 4
WHERE SSN = 5;
UPDATE Employee
SET SuperID = 5
WHERE SSN = 6;
select * From Departement
Insert into Departement(DNum,DName, SSN, HireDate)
values (1, 'HR', NULL, '2020-01-01'),
(2, 'IT', NULL, '2021-02-01');
select * From Dept_Location
Insert into Dept_Location(DNum,DLocation)
values (1, 'Muscat'),
(2, 'Sohar');
select * From Project
Insert into Project(PNum,PName, DNum, City, PLocation )
values (100, 'ProjectA', 1, 'Muscat', 'HQ Building'),
(101, 'ProjectB', 2, 'Salalah', 'Branch Office');
select * From EmployeeDependent
Insert into EmployeeDependent(SSN, DependentName, BirthDay, Gender)
values (4, 'Ali', '2010-04-05', 1),
(5, 'Laila', '2012-09-15', 0);
--Check the existing SSNs in the Employee table
select SSN From Employee
select * From My_work
Insert into My_work(SSN, PNum, M_hours)
values ( 4, 100, 23),
( 5, 101, 24);