-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggers.sql
49 lines (37 loc) · 979 Bytes
/
triggers.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
use BloodTransfusion;
GO
DROP TRIGGER IF EXISTS LogThePacketTransfersBetweenBloodBanks
GO
DELETE FROM PacketTransfer
GO
CREATE TRIGGER LogThePacketTransfersBetweenBloodBanks
ON BloodPacket
AFTER UPDATE
AS
BEGIN
PRINT SYSDATETIME()
INSERT INTO PacketTransfer VALUES (
(SELECT TOP 1 inserted.id FROM inserted),
(SELECT TOP 1 inserted.locatedAt FROM inserted),
(SYSDATETIME())
)
END
GO
UPDATE BloodPacket SET locatedAt = 2 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 1 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 2 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 1 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 2 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 1 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 2 WHERE id = 1
GO
UPDATE BloodPacket SET locatedAt = 1 WHERE id = 1
GO
SELECT * FROM PacketTransfer ORDER BY transferDate
GO