IDENT_CURRENT value in case of INSERT Trigger

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 266
CREATE TABLE Table2 ( ID int identity( 10, 1), Name VARCHAR(100))
GO
CREATE TRIGGER Tri_CheckIdentCurrent ON Table2
FOR INSERT
AS
INSERT INTO Table2 select name+' Inserted from Trigger' from inserted
GO

INSERT Table2 VALUES( 'LAST Insert statemnt-Table2')
GO
SELECT * FROM Table2
/*
ID Name
10 LAST Insert statemnt-Table2
11 LAST Insert statemnt-Table2 Inserted from Trigger
*/

SELECT IDENT_CURRENT('Table2') Table2IDUsingIdentCurrent
/*
Table2IDUsingIdentCurrent
11
*/
DROP TABLE Table2


In above code, am trying to explain the behavior of IDENT_CURRENT() function in case of having INSERT TRIGGER on the table and also the trigger is trying to insert one more record into same table... Then, IDENT_CURRENT() gives you the value after firing TRIGGER...

Comments or Responses

Login to post response