Click here to Skip to main content
15,888,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi to all,

I create after insert trigger on EMP1 table.In EMP1 table i don't have identity column, in that trigger i insert data into EMP2 table.In EMP2 table i have identity (ID)column with auto increment 1. After insert the data into EMP1 data automatically inserted in EMP2 and also created a ID fot that employee. in this case how to get that ID from EMP2 table in that trigger ?


could anyone know about this tell me.

Regards
Nanda Kishore.CH
Posted
Updated 5-Aug-13 19:13pm
v2

create table emp1 
(
name varchar(20)
)
go
create table emp2 
(
id int identity(1,1),
name varchar(20)
)
go
create trigger instrg_emp1
on emp1
after insert
as
begin
insert into emp2(name) 
select name from inserted
select @@identity
end
go
insert emp1 values('denzil')
go
 
Share this answer
 
select @id = id from emp2 where empname = @empname
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900