Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple trigger question

Status
Not open for further replies.

Gaylord

Technical User
Sep 26, 2002
49
0
0
DE
Hi,

This is my first attempt at a trigger and I seem to be having a bit of a brain freeze!

I insert a record into a table with basic user info, a trigger then grabs the newly inserted information and puts it into a second table for later use. However whenever i do this it takes everything that is currently in the table (new_user) and adds it to the second table (data)

I think I am being very slow here, but help please!

CREATE TRIGGER [INSERT_RECORD]
ON [dbo].[new_user]
FOR INSERT
AS
INSERT INTO data (emp_no)
SELECT new_user.user_id
FROM new_user
WHERE new_user.user_id = user_id

Thanks

Jamie
 
You almost got it. You want to referance a virtual table called inserted
Code:
CREATE TRIGGER [INSERT_RECORD] 
ON [dbo].[new_user] 
FOR INSERT 
AS
INSERT INTO data (emp_no) 
SELECT user_id
FROM inserted

Denny

--Anything is possible. All it takes is a little research. (Me)
 
CREATE TRIGGER [INSERT_RECORD]
ON [dbo].[new_user]
FOR INSERT
AS
INSERT INTO data (emp_no)
SELECT new_user.user_id
FROM inserted
WHERE new_user.user_id = user_id

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Code:
CREATE TRIGGER INSERT_RECORD
ON dbo.new_user
FOR INSERT
AS
INSERT INTO data (emp_no)
SELECT user_id
FROM  inserted
 
Thank you so much. I will try the next few steps now!

Cheers Guys

Jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top