-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEggFarmProject DataBase.txt
175 lines (124 loc) · 4.74 KB
/
EggFarmProject DataBase.txt
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
DROP DATABASE IF EXISTS EggFarm;
CREATE DATABASE EggFarm;
USE EggFarm;
CREATE TABLE Customer(
custId VARCHAR(10) NOT NULL,
name VARCHAR(50) NOT NULL,
shopName VARCHAR(50),
address VARCHAR(50) NOT NULL,
mobileNumber INT NOT NULL,
CONSTRAINT PRIMARY KEY(custId),
CONSTRAINT name_address UNIQUE(name,address)
);
CREATE TABLE Orders(
orderId VARCHAR(10) NOT NULL,
custId VARCHAR(10) NOT NULL,
orderDate VARCHAR(20) NOT NULL,
orderTime VARCHAR(20) NOT NULL,
CONSTRAINT PRIMARY KEY(orderId),
CONSTRAINT FOREIGN KEY (custId) REFERENCES Customer(custId)
ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE Product(
productId VARCHAR(10) NOT NULL,
description VARCHAR(50) NOT NULL,
unitprice DOUBLE(10, 2) NOT NULL,
qtyOnHand INT NOT NULL,
CONSTRAINT PRIMARY KEY(productId)
);
CREATE TABLE OrderDetail(
orderId VARCHAR(10) NOT NULL,
productId VARCHAR(10) NOT NULL,
qty INT NOT NULL,
CONSTRAINT FOREIGN KEY (orderId) REFERENCES Orders(orderId)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (productId) REFERENCES Product(productId)
ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE Cage(
cageId VARCHAR(10) NOT NULL,
noOfHen INT NOT NULL,
qtyOnFood VARCHAR(10) NOT NULL,
qtyOnVitamin VARCHAR(10) NOT NULL,
CONSTRAINT PRIMARY KEY(cageId)
);
CREATE TABLE Employee(
empId VARCHAR(10) NOT NULL,
name VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL,
mobileNumber INT NOT NULL,
registryDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),
CONSTRAINT PRIMARY KEY(empId)
);
CREATE TABLE EggBucket(
eggBucketId VARCHAR(10) NOT NULL,
cageId VARCHAR(10) NOT NULL,
empId VARCHAR(10) NOT NULL,
dates DATE NOT NULL,
times VARCHAR(20) NOT NULL,
qty INT NOT NULL,
CONSTRAINT PRIMARY KEY(eggBucketId),
CONSTRAINT FOREIGN KEY (cageId) REFERENCES Cage(cageId)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (empId) REFERENCES Employee(empId)
ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE EggBucketDetail(
eggBucketId VARCHAR(10) NOT NULL,
productId VARCHAR(10) NOT NULL,
qty INT NOT NULL,
CONSTRAINT FOREIGN KEY (eggBucketId) REFERENCES EggBucket(eggBucketId)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (productId) REFERENCES Product(productId)
ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE Attendance(
empId VARCHAR(10) NOT NULL,
Dates VARCHAR(25) NOT NULL,
checkIn VARCHAR(25) NOT NULL,
checkOut VARCHAR(25) NOT NULL,
workingHour VARCHAR(25) NOT NULL,
CONSTRAINT FOREIGN KEY (empId) REFERENCES Employee(empId)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT empId_Dates UNIQUE(empId,Dates)
);
CREATE TABLE Users(
userName VARCHAR(20) NOT NULL,
name VARCHAR(45) NOT NULL,
email VARCHAR(30) NOT NULL,
password VARCHAR(500) NOT NULL,
roleType VARCHAR(20) NOT NULL,
CONSTRAINT PRIMARY KEY(userName,email),
CONSTRAINT userName_email UNIQUE(userName,email)
);
ALTER TABLE EggBucket
MODIFY COLUMN times VARCHAR(20);
base64 -> password reset
create table temp(
name varchar(500),
password varchar(500)
);
insert into temp(name, password) values('danuja', md5('abc'));
insert into temp(name, password) values('deshan', md5('123'));
SELECT * FROM temp WHERE password = md5('abc');
SELECT * FROM temp WHERE password = md5('123');
INSERT INTO Users VALUES(?, ?, ?, md5(?), ?);
);
select * from Users where userName = 'danuvdeshan' && password = md5('deshan1234');
select * from Users where userName = 'dadnuvdeshan' || email = 'danujagreruv@gmail.com'&& password = md5('deshan1234');
select * from Users where userName = 'danu' && password = md5('12345678');
select * from Users where (userName = 'danu' || email = 'danu' ) && password = md5('12345678d');
SELECT custId,productId,qty,orderDate,orderTime FROM Orders INNER JOIN OrderDetail ON Orders.orderId = OrderDetail.orderId
WHERE MONTH(orderDate) = MONTH(curdate());
SELECT custId,productId,qty,orderDate,orderTime FROM Orders INNER JOIN OrderDetail ON Orders.orderId = OrderDetail.orderId GROUP BY YEAR(orderDate), MONTH(orderDate),
DATENAME(MONTH, orderDate)
ORDER BY 1,2;
ORDER BY YEAR(orderDate), MONTH(orderDate) GROUP BY YEAR(orderDate), MONTH(orderDate);
SELECT YEAR(orderDate) [Year], MONTH(orderDate) [Month],
DATENAME(MONTH,orderDate) [Month Name], COUNT(1) [Sales Count]
FROM #Sales
GROUP BY YEAR(orderDate), MONTH(orderDate),
DATENAME(MONTH, orderDate)
ORDER BY 1,2
SELECT orderId, description,qty,unitprice FROM OrderDetail INNER JOIN Product ON OrderDetail.productId = Product.productId;
INSERT INTO Users VALUES('danu', 'Danuja', 'danujagreru@gmail.com', md5(12345678), 'Owner');