-
Notifications
You must be signed in to change notification settings - Fork 1
/
Preference Triggers
135 lines (104 loc) · 2.81 KB
/
Preference Triggers
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
CREATE TRIGGER update_preferences_on_reservation
ON Marti_Rezervation
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET marti_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Marti_Rezervation preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after ferry ticket
CREATE TRIGGER update_preferences_after_ferry_ticket
ON Ferry_Ticket
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET ferry_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Ferry_ticket preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after bus ticket
CREATE TRIGGER update_preferences_after_bus_ticket
ON bus_ticket
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET bus_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Bus preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after izban journey
CREATE TRIGGER update_preferences_after_izban_journey
ON Izban_journey
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET izban_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Izban preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after train ticket
CREATE TRIGGER update_preferences_after_train_ticket
ON Train_Ticket
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET train_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Train preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after flight ticket
CREATE TRIGGER update_preferences_after_flight_ticket
ON Flight_Ticket
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET airplane_trip_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Flight preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;
--Trigger for updating preference after car rezervation
CREATE TRIGGER update_preferences_after_car_rezervation
ON Car_rent_rezervation
AFTER INSERT
AS
BEGIN
DECLARE @Card_id INT;
SELECT @Card_id = Card_id
FROM inserted;
UPDATE Preferences
SET car_rent_preference = 1
WHERE Card_id = @Card_id;
-- Add a message
PRINT 'Renting a car preference updated for Card_id: ' + CAST(@Card_id AS VARCHAR);
END;