29. maj 2001 - 09:40Der er
7 kommentarer og 2 løsninger
I need a trigger thats return the @@identity on Insert, Update, and Delete
Hola!
I have two tabels, table1 wich gets updated, tabel2 which I want to note which rows in tabel1 who gets changed.
So I need a trigger thats get fired when something happens in tabel1, and I need to return the primarykey from tabel1 on that row who gets change and store that value in tabel2.
So what I have tried is somthing like this:
Create trigger dbo.tr_change_on_tabel1 On table1 For { Insert | Delete | Update } With encryption as Declare id numeric Select @@identity Into id
insert into tabel2 (tabel, id) values(\'tabel1\', id)
This last one would be great if it could be replaced by a stored_procedure as well.
It would be great if you could help me out with this.
I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
Create trigger dbo.tr_change_on_tabel1 On table1 For { Insert | Delete | Update } With encryption as Declare @id numeric Select @@identity as @id from inserted i
insert into tabel2 (tabel, id) values(\'tabel1\', @id)
yes, inserted is just the temp. table that the trigger creates when an insert,update, delete occurs (the changed data is placed in the temp. table!) - as far as I know :O)
deleted : Contains the deleted rows which mean the rows that are actually deleted and the rows that are updated! The rows before they are updated are in the deleted table.
Inserted : Contains the inserted rows which mean the rows that are actually inserted and the rows that are updated! The rows after they are updated are in the inserted table. So make a JOIN between the deleted and the inserted table to figure out which rows are updated.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.