-
Notifications
You must be signed in to change notification settings - Fork 1
/
trigger_to_update_company.sql
63 lines (52 loc) · 1.05 KB
/
trigger_to_update_company.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
USE [Cimatec]
GO
CREATE TRIGGER TGR_COMPANY_INSERT
ON [dbo].[Bomix_Cliente]
FOR INSERT
AS
BEGIN
DECLARE
@Recno INT,
@NomeFantasia VARCHAR(20),
@CNPJ VARCHAR(14),
@Email VARCHAR(100)
SELECT @Recno = [Recno]
,@NomeFantasia = [NomeFantasia]
,@CNPJ = [CNPJ]
,@Email = [Email] FROM inserted
INSERT INTO [dbo].[COMPANY]
values (@NomeFantasia,@Email,@CNPJ,@Recno)
END
GO
CREATE TRIGGER TGR_COMPANY_UPDATE
ON [dbo].[Bomix_Cliente]
FOR UPDATE
AS
BEGIN
DECLARE
@Recno INT,
@NomeFantasia VARCHAR(20),
@CNPJ VARCHAR(14),
@Email VARCHAR(100)
SELECT @Recno = [Recno]
,@NomeFantasia = [NomeFantasia]
,@CNPJ = [CNPJ]
,@Email = [Email] FROM inserted
UPDATE [dbo].[COMPANY]
SET [NAME] = @NomeFantasia
,[EMAIL] = @Email
,[CNPJ] = @CNPJ
WHERE [RECNO] = @Recno
END
GO
CREATE TRIGGER TGR_COMPANY_DELETE
ON [dbo].[Bomix_Cliente]
FOR DELETE
AS
BEGIN
DECLARE
@Recno INT
SELECT @Recno = [Recno] FROM deleted
DELETE [dbo].[COMPANY] WHERE [RECNO] = @Recno
END
GO