-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database Script
194 lines (159 loc) · 4.49 KB
/
Database Script
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
185
186
187
188
189
190
191
192
193
194
create database IndustrialWatchFYP
use IndustrialWatchFYP
---1. Creating RawMaterial Table for Violations
CREATE TABLE RawMaterial (
id INT not null identity(1,1) PRIMARY KEY,
name VARCHAR(20),
);
---2. Product Creation----
CREATE TABLE Product (
product_number varchar(40) PRIMARY KEY,
name VARCHAR(25),
inspection_angles varchar(50),
);
---3. ProductFormula Creation----
create table ProductFormula(
id INT not null identity(1,1) PRIMARY KEY,
product_number varchar(40) foreign key references Product(product_number),
unit varchar(5),
raw_material_id int foreign key references RawMaterial(id),
quantity int
);
-- 4. Create Stock Table
CREATE TABLE Stock(
stock_number varchar(40) PRIMARY KEY,
raw_material_id int FOREIGN KEY REFERENCES RawMaterial(id),
quantity INT,
price_per_kg MONEY,
purchased_date date,
);
-- 5. Create ProductLink Table
CREATE TABLE ProductLink(
id int identity(1,1) primary key,
packs_per_batch int,
piece_per_pack int,
rejection_tolerance float,
product_number VARCHAR(40) foreign key references Product(product_number)
);
-- 6. Create Batch Table
CREATE TABLE Batch (
batch_number VARCHAR(40) not null PRIMARY KEY,
product_link_id int foreign key references ProductLink(id),
manufacturing_date date,
batch_yield float,
defected_pieces int
);
-- 7. Create StockInBatch Table
create table StockInBatch(
id int identity(1,1) primary key,
stock_number varchar(40) Foreign Key references Stock(stock_number),
batch_number varchar(40) foreign key references Batch(batch_number)
);
-- 8. Create Section Table
CREATE TABLE Section (
id INT not null identity(1,1) PRIMARY KEY,
name VARCHAR(25),
status int
);
------------------------
-- 9. Create Rule Table
CREATE TABLE ProductivityRule(
id INT not null identity(1,1) PRIMARY KEY,
name VARCHAR(20)
);
-------------------------
-- 10. Create SectionRule Table
CREATE TABLE SectionRule (
id INT not null identity(1,1) PRIMARY KEY,
section_id INT,
rule_id INT,
fine MONEY,
allowed_time TIME,
date_time DateTime,
FOREIGN KEY (section_id) REFERENCES Section(id),
FOREIGN KEY (rule_id) REFERENCES ProductivityRule(id)
);
------------------------
-- 11. Create users Table
CREATE TABLE Users (
id INT not null identity(1,1) PRIMARY KEY,
username VARCHAR(25),
password VARCHAR(25),
user_role VARCHAR(20),
);
------------------------
-- 12. Create JobRole Table
CREATE TABLE JobRole (
id int not null identity(1,1) PRIMARY KEY,
name VARCHAR(30),
);
------------------------
-- 13. Create Employee Table
CREATE TABLE Employee (
id INT not null identity(1,1) PRIMARY KEY,
name VARCHAR(30),
salary MONEY,
job_role_id int foreign key references JobRole(id),
job_type VARCHAR(15),
date_of_joining DATE,
gender VARCHAR(6),
user_id INT,
FOREIGN KEY (user_id) REFERENCES Users(id)
);
------------------------
--14. Create EmployeeSection Table for many to many relationship
CREATE TABLE EmployeeSection(
id int not null identity(1,1) PRIMARY KEY,
employee_id int,
section_id int,
date_time DateTime,
FOREIGN KEY (employee_id) REFERENCES Employee(id),
FOREIGN KEY (section_id) REFERENCES Section(id)
);
------------------------
--15. Create EmployeeProductivity Table for storing Productivity of Employee.
CREATE TABLE EmployeeProductivity(
id int not null identity(1,1) PRIMARY KEY,
employee_id int,
productivity float,
productivity_month Date,
FOREIGN KEY (employee_id) REFERENCES Employee(id),
);
--16. Create EmployeeImages Table
CREATE TABLE EmployeeImages(
id int not null identity(1,1) PRIMARY KEY,
employee_id int,
image_url varchar(MAX),
FOREIGN KEY (employee_id) REFERENCES Employee(id),
);
------------------------
-- 17. Create Attendance Table
CREATE TABLE Attendance (
id INT not null identity(1,1) PRIMARY KEY,
check_in TIME,
check_out TIME,
attendance_date DATE,
employee_id INT,
FOREIGN KEY (employee_id) REFERENCES Employee(id)
);
------------------------
-- 18. Create Violation Table
CREATE TABLE Violation (
id INT not null identity(1,1) PRIMARY KEY,
employee_id INT,
rule_id INT,
date Date,
start_time Time,
end_time Time,
FOREIGN KEY (rule_id) REFERENCES ProductivityRule(id),
FOREIGN KEY (employee_id) REFERENCES Employee(id)
);
------------------------
--19. Creating Images Table for Violations
CREATE TABLE ViolationImages(
id int not null identity(1,1) PRIMARY KEY,
violation_id int,
image_url varchar(Max),
FOREIGN KEY (violation_id) REFERENCES Violation(id),
capture_time Time
);