Reputation: 353
I created a trigger so that after two friends are added in a social media website this trigger is outputted. I am trying to output a temporary trigger so that as soon they are friend in the output view a statement is shown. What is the syntax error exactly on Output in the following code please? If there could be improvement to the code inform me pls.
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
Upvotes: 0
Views: 283
Reputation: 27862
I think you want the PRINT statement:
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;
Print 'Trigger : '+@FriendA+' and '+@FriendB+' become friends.'
END
GO
TRIGGERS ARE SET BASED. Do NOT apply "row by row" logic in a trigger.
http://www.jimmcleod.net/blog/index.php/2008/06/05/triggers-set-based-not-row-based/
Upvotes: 1