-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery.sql
More file actions
184 lines (137 loc) · 3.88 KB
/
SQLQuery.sql
File metadata and controls
184 lines (137 loc) · 3.88 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
create database ProjectManagement;
use ProjectManagement
go
create table Admin (
id int,
name varchar(20) not null,
password varchar(20) not null,
constraint Admin_pk primary key (id),
);
create table project_manager (
id int primary key,
name varchar(20) not null,
password varchar(20) not null,
position varchar(20) not null,
admin_id int,
--constraint project_manager_pk primary key (id),
--constraint admin_manager_fk foreign key (admin_id)
--references admin (id)
);
alter table project_manager
add admin_id int
alter table project_manager
add constraint admin_manager_fk foreign key (admin_id)
references admin (id)
alter table team_leader
add admin_id int
alter table team_leader
add constraint admin_leader_fk foreign key (admin_id)
references admin (id)
alter table employee
add admin_id int
alter table employee
add constraint admin_employee_fk foreign key (admin_id)
references admin (id)
alter table projects
add admin_id int
alter table projects
add constraint admin_projects_fk foreign key (admin_id)
references admin (id)
create table team_leader (
id int,
name varchar(20) not null,
password varchar(20) not null,
position varchar(20) not null,
pm_id int,
admin_id int,
constraint team_leader_pk primary key (id),
constraint manager_leader_fk foreign key (pm_id)
references project_manager (id),
--constraint admin_leader_fk foreign key (admin_id)
--references admin (id)
);
create table employee (
id int,
name varchar(20) not null,
password varchar(20) not null,
position varchar(20) not null,
penalty int,
tl_id int,
pm_id int,
admin_id int,
constraint employee_manager_pk primary key (id),
constraint leader_employee_fk foreign key (tl_id)
references team_leader (id),
constraint manager_employee_fk foreign key (pm_id)
references project_manager (id),
--constraint admin_employee_fk foreign key (admin_id)
--references admin (id)
);
create table projects (
id int,
project_name varchar(20) not null,
progress varchar(20) not null,
tl_id int,
pm_id int,
constraint projects_pk primary key (id),
constraint leader_projects_fk foreign key (tl_id)
references team_leader (id),
constraint manager_projects_fk foreign key (pm_id)
references project_manager (id)
);
create table tasks (
id int,
task_name varchar(20) not null,
task_state varchar(20) not null,
employee_id int,
tl_id int,
project_id int,
constraint tasks_pk primary key (id),
constraint employee_tasks_fk foreign key (employee_id)
references employee (id),
constraint leader_tasks_fk foreign key (tl_id)
references team_leader (id),
constraint projects_tasks_fk foreign key (project_id)
references projects (id)
);
--select project_name, progress, pm_id from projects p inner join project_manager m
--on p.pm_id = 2;
--select project_name, progress, pm_id from projects p where p.pm_id = 1
create table attendance (
id int identity(1,1) primary key,
enter_time varchar(20),
exit_time varchar(20),
date varchar(20),
employee_id int,
constraint employee_attendance_fk foreign key (employee_id)
references employee (id)
);
create table vacation (
id int identity(1,1) primary key,
day_from varchar(20),
day_to varchar(20),
reson varchar(20),
state varchar(20),
employee_id int,
constraint employee_vacation_fk foreign key (employee_id)
references employee (id)
);
create table reports (
id int identity(1,1) primary key,
report varchar(100),
tl_id int,
constraint leader_reports_fk foreign key (tl_id)
references team_leader (id)
);
--create table penalties (
-- id int identity(1,1) primary key,
-- penalty int,
-- employee_id int,
-- constraint employee_penalties_fk foreign key (employee_id)
-- references employee (id)
--);
--select date, employee_id from attendance a, employee e
--where a.employee_id = e.id and e.pm_id = 1
--select date, employee_id, name from vacation v, employee e
--where v.employee_id = e.id and e.pm_id = 3
--drop table vacation, attendance