-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkavya-queries.sql
93 lines (73 loc) · 2.18 KB
/
kavya-queries.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
Use Bluedart;
SELECT * FROM Branch WHERE name="Bluedartudaipur"
SELECT * FROM Branch WHERE branchid="1"
SELECT branchID FROM Branch WHERE name = "BluedartDoon"
SELECT branchID FROM Branch_vehicle WHERE vehicleid="UK D 7879"
SELECT phonenumber FROM Branch_phonenumber WHERE branchid = "2"
SELECT name FROM Branch WHERE email = "[email protected]"
SELECT zipcodeID FROM Branch WHERE name="Bluedartudaipur"
-- For email verification
DELIMITER //
CREATE TRIGGER EMAIL_VERIFICATION
BEFORE INSERT
ON Customer
FOR EACH ROW
BEGIN
IF NEW.email NOT LIKE '%@%.__%' THEN
SIGNAL SQLSTATE VALUE '45000'
SET MESSAGE_TEXT = '[table:Customer] - email column is not valid';
END IF;
END;//
insert into Customer values(7,"Demo","SIT","Demogmail",1);
-- For valid phone number
DELIMITER //
CREATE TRIGGER VALID_PH
BEFORE INSERT
ON Customer_phonenumber
FOR EACH ROW
BEGIN
IF LENGTH(NEW.phonenumber)<10 THEN
SIGNAL SQLSTATE VALUE '45000'
SET MESSAGE_TEXT = '[table:Customer_phonenumber] - PHONE NO. column is not valid';
END IF;
END;//
insert into Customer_phonenumber values ("555",3);
-- For valid name
DELIMITER //
CREATE TRIGGER VALID_NAME
BEFORE INSERT
ON Customer
FOR EACH ROW
BEGIN
IF ISNULL(NEW.name) THEN
SIGNAL SQLSTATE VALUE '45000'
SET MESSAGE_TEXT = '[table:Customer] - NAME column is not valid';
END IF;
END;//
insert into Customer values(8,NULL,"Pune","[email protected]",5);
-- For checking if the Zipcode is valid
DELIMITER //
CREATE TRIGGER VALID_Zipcode
BEFORE INSERT
ON Zipcode
FOR EACH ROW
BEGIN
IF NOT LENGTH(NEW.zipcodeid)=10 THEN
SIGNAL SQLSTATE VALUE '45000'
SET MESSAGE_TEXT = '[table:Zipcode] - zipcode is not valid';
END IF;
END;//
INSERT INTO Zipcode (zipcodeid,state,city) values(7,"maharashtra","Pune");
-- To check for a valid date”
DELIMITER //
CREATE TRIGGER VALID_DATE
BEFORE INSERT
ON Transfer
FOR EACH ROW
BEGIN
IF NOT ISDATE(NEW.date) THEN
SIGNAL SQLSTATE VALUE '45000'
SET MESSAGE_TEXT = '[table:Tranfer] - Date is not valid';
END IF;
END;//
insert into Transfer values (6,"a",'404',"Pickup","RJ 7879",3,4,4,3);