BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Update trigger

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Brian Paine
Guest





PostPosted: Sat Apr 24, 2004 1:05 pm    Post subject: Update trigger Reply with quote



I am using SQL Server 2000 and would like to create an update trigger that
populates another table with some of the values of the columns of the
current table. How would I go about this?

thanks

Brian


Back to top
Alain Quesnel
Guest





PostPosted: Sat Apr 24, 2004 11:29 pm    Post subject: Re: Update trigger Reply with quote



CREATE TRIGGER trgInsertCustomer ON CUSTOMERS
FOR INSERT
AS

insert into ACTIVITY_TABLE
select * from INSERTED

This assumes the existence of a table called ACTIVITY_TABLE. For this
example to work, ACTIVITY_TABLE has to have a structure that is identical to
CUSTOMERS.

The INSERTED table represents all rows currently being inserted (i.e. the
new rows) into the table for which the trigger was created. It only exists
in memory, and within the context of an update or insert trigger.

If you want, you can use only certain values from the INSERTED table, add
some of your own (getdate(), username, etc.) and insert that into
ACTIVITY_TABLE. ACTIVITY_TABLE would then have a different structure.

--

Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]

www.logiquel.com


"Brian Paine" <bpaine (AT) snowhill (DOT) com> wrote

Quote:
I am using SQL Server 2000 and would like to create an update trigger that
populates another table with some of the values of the columns of the
current table. How would I go about this?

thanks

Brian





Back to top
Brian Paine
Guest





PostPosted: Tue Apr 27, 2004 1:38 am    Post subject: Re: Update trigger Reply with quote



Thank you, this helped.

Alain Quesnel wrote:

Quote:
CREATE TRIGGER trgInsertCustomer ON CUSTOMERS
FOR INSERT
AS

insert into ACTIVITY_TABLE
select * from INSERTED

This assumes the existence of a table called ACTIVITY_TABLE. For this
example to work, ACTIVITY_TABLE has to have a structure that is identical to
CUSTOMERS.

The INSERTED table represents all rows currently being inserted (i.e. the
new rows) into the table for which the trigger was created. It only exists
in memory, and within the context of an update or insert trigger.

If you want, you can use only certain values from the INSERTED table, add
some of your own (getdate(), username, etc.) and insert that into
ACTIVITY_TABLE. ACTIVITY_TABLE would then have a different structure.

--

Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]

www.logiquel.com

"Brian Paine" <bpaine (AT) snowhill (DOT) com> wrote in message
news:408a6631$1 (AT) newsgroups (DOT) borland.com...
I am using SQL Server 2000 and would like to create an update trigger that
populates another table with some of the values of the columns of the
current table. How would I go about this?

thanks

Brian




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.