bongobilly
asked on
SQL trigger update insert records
Here is my code for SQL trigger
ALTER TRIGGER [dbo].[AfterUPDATETrigger] on [dbo].[Datatable]
FOR UPDATE
AS DECLARE @cola int,@Colb nvarchar(10)
SELECT @cola = ins.cola from inserted ins
SELECT @Colb = ins.colb from inserted ins
IF @colb ='d'
BEGIN
INSERT INTO Datatableb(colz,colx)
VALUES(@colb,@cola)
END
This is the data in Datatable
Cola colb colc
1 a 30
2 a 30
3 a 30
If I update colb = d where colc = 30
I only insert 1 row into datatableB
I want to get all 3 updates to be entered into datatableb
ALTER TRIGGER [dbo].[AfterUPDATETrigger]
FOR UPDATE
AS DECLARE @cola int,@Colb nvarchar(10)
SELECT @cola = ins.cola from inserted ins
SELECT @Colb = ins.colb from inserted ins
IF @colb ='d'
BEGIN
INSERT INTO Datatableb(colz,colx)
VALUES(@colb,@cola)
END
This is the data in Datatable
Cola colb colc
1 a 30
2 a 30
3 a 30
If I update colb = d where colc = 30
I only insert 1 row into datatableB
I want to get all 3 updates to be entered into datatableb
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Currently you only work with arbitrary values.
This should do it:
Open in new window