我创建了一个触发器,以便在社交媒体网站中添加两个朋友之后输出此触发器。我正在尝试输出一个临时触发器,以便在输出视图中他们很快就会显示一条语句。请问以下代码中输出的语法错误是什么?如果代码有可能改进,请告知我。
CREATE TRIGGER [a01].[trg_addedFriend]
ON [a01].[tbl_friends]
AFTER INSERT
AS
BEGIN
DECLARE @FriendA NVARCHAR(45)
DECLARE @FriendB NVARCHAR(45)
SELECT @FriendA = ownerAccountID
FROM inserted;
SELECT @FriendB = friendAccountID
FROM inserted;
OUTPUT 'Trigger : '+@FriendA+' and '+@FriendB+' become friends.'
END
GO
答案 0 :(得分:1)
我想你想要PRINT声明:
创建触发器[a01]。[trg_addedFriend] ON [a01]。[tbl_friends] 插入后
AS
BEGIN
DECLARE @FriendA NVARCHAR(45)
DECLARE @FriendB NVARCHAR(45)
SELECT @FriendA = ownerAccountID
FROM inserted;
SELECT @FriendB = friendAccountID
FROM inserted;
Print 'Trigger : '+@FriendA+' and '+@FriendB+' become friends.'
END
GO
触发器基于设置。不要逐行申请""触发器中的逻辑。
http://www.jimmcleod.net/blog/index.php/2008/06/05/triggers-set-based-not-row-based/