Insert Triggers - how do i detect the values that were inserted

I'm looking to insert the values inserted in a table onto another server - how do i detect the orgional values - i know of something called magic tables - is this the best way?
CREATE TRIGGER trgInsert
ON TABLE1.DBO.User_Master
FOR INSERT
AS 
 
GO
 
BEGIN TRANSACTION
DECLARE @ERR INT
 
	INSERT INTO TABLE2.DBO.USER_MASTER(USERNAME, PASSWORD)
	VALUES(????????,?????????)
 
SET @ERR = @@Error
IF @ERR = 0    
             BEGIN
                           ROLLBACK TRANSACTION
 
             END
ELSE
             BEGIN
                           COMMIT TRANSACTION
             END

Open in new window

paulCardiffAsked:
Who is Participating?
 
imitchieConnect With a Mentor Commented:
BEGIN TRANSACTION
DECLARE @ERR INT
 
        INSERT INTO TABLE2.DBO.USER_MASTER(USERNAME, PASSWORD)
        SELECT USER, PASSWD FROM INSERTED -- direct copy
 
SET @ERR = @@Error
IF @ERR = 0    
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
the magic table inserted will contain the new values  and the deleted contain the deleted rows
In sql 2005 there is a new feature for OUTPUTing the modified values to a table
0
 
imitchieCommented:
They are called INSERTED and DELETED
reference them as you would any table, i.e.
SELECT X, Y from INSERTED
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
paulCardiffAuthor Commented:
Thanks for the info,

Sorry what is that new feature, and ideally provide any sample syntax if possible?
0
 
paulCardiffAuthor Commented:
sorry sent reply before seeing imitchies reply -

So is "SELECT X, Y from INSERTED" - is x and y just the standard field names?
0
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
0
All Courses

From novice to tech pro — start learning today.