 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Brian Paine Guest
|
Posted: Sat Apr 24, 2004 1:05 pm Post subject: Update trigger |
|
|
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
|
Posted: Sat Apr 24, 2004 11:29 pm Post subject: Re: Update trigger |
|
|
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
|
Posted: Tue Apr 27, 2004 1:38 am Post subject: Re: Update trigger |
|
|
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 |
|
 |
|
|
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
|
|