-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggers and views.sql
60 lines (45 loc) · 1.23 KB
/
triggers and views.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
-- USE COVIDVACCINE
/* view for order id , customer(HMO) , supplier
CREATE VIEW HMO_ORDER_SUPPLIER AS
SELECT O.OID AS 'Order number', H.HMONAME AS 'Customer' , S.SNAME AS 'Supplier'
FROM HMO_TABLE H
JOIN ORDER_TABLE O
ON (O.HMOLICENSE = H.HMOLICENSE)
JOIN SUPPLIER_TABLE S
ON(O.SLICENSE = S.SLICENSE);
*/
/* view for person name blood type and vaccine status
CREATE VIEW PERSON_BLOODTYPE_VACCINESTATUS AS
SELECT P.FNAME , P.LNAME , M.BLOODTYPE , M.VACCINESTATUS
FROM PERSON_TABLE P
INNER JOIN MEDICALRECORD_TABLE M
ON (P.PID=M.PID AND M.BLOODTYPE = 'B-')
ORDER BY P.FNAME;
*/
/* trigger that up in 1 in town population every time we add person
DELIMITER $$
CREATE TRIGGER UPDATE_POPULATION
AFTER INSERT ON PERSON_TABLE
FOR EACH ROW
BEGIN
UPDATE TOWN_TABLE SET POPULATION = POPULATION + 1
WHERE TNAME = NEW.LIVEIN;
END$$
DELIMITER ;
*/
/* trigger that update stock in hmo after
delivery status become delivered
DELIMITER $$
CREATE
TRIGGER UPDATE_ORDER AFTER UPDATE
ON ORDER_TABLE
FOR EACH ROW BEGIN
IF NEW.STATUS = 'DELIVERED' THEN
UPDATE HMO_TABLE H
JOIN ORDER_TABLE O
SET H.STOCK = H.STOCK + O.QUANTITY
WHERE O.HMOLICENSE=H.HMOLICENSE;
END IF;
END$$
DELIMITER ;
*/