August 3, 2005 at 12:46 am
create table TZ(Z_id int identity(1,1) primary key, z_name varchar(20) not null)
select * from TZ
delete tz where Z_id in (3)
insert into TZ values('r u')
create table TY(Y_id int identity(100,1) primary key, y_name varchar(10) not null)
select * from TY
insert into TY values('2wards u')
create trigger Ztrigger
on TZ for
insert as
begin
//declare @value varchar(10)
//set @value = TZ.z_name
//insert TY values(@value)
insert TY values(' ')
end
insert tz values('glacier') -- Triggering the trigger through insert statement.
The scenario is i have created two tables TZ&TY with identical fields, and creating a trigger(on TZ table) to insert values automatically to TY, but on Triggering the trigger by using an insert statement... I want glacier to be the value of Y_name in the table TY. Can some1 let me know how do i do that...(I thought of creating a local variable but that idea failed.)
Regards
Arun
August 3, 2005 at 1:38 am
You use the virtual table INSERTED, which contains all the rows that where inserted by the statement that triggered the trigger.
create trigger Ztrigger
on TZ for
insert as
begin
INSERT INTO TY (y_name)
SELECT z_name FROM INSERTED
end
August 3, 2005 at 2:55 am
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply