Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2008, 07:21 PM
ik ik is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trigger : after update insert into second table

I have two tables in SQL Server firsttable and secondtable.
 I would like to make an trigger in firsttable that after update some column to insert some values (from firsttable) into secondtable.
I have tried to read updated row id with @@identity, but does not works.
Please, help.

 
Old January 28th, 2009, 12:00 PM
Registered User
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Did you ever figured this out?

I am having the same problem. I was asked to create a log table that will collect changes in few fields from 1st table.
 
Old January 28th, 2009, 12:52 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Can you post your code? What you have so far?
 
Old January 29th, 2009, 07:45 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
CREATE  TRIGGER dbo.trgFirstTable_Update
ON dbo.FirstTable
AFTER  UPDATE
AS
IF  UPDATE(Col1)ORUPDATE(Col2)
INSERT SecondTable
(
SomeCol
)
SELECT ft.SomeCol
FROM dbo.FirstTable AS ft
INNER JOIN inserted AS i ON i.pkCol = ft.pkCol
 
Old January 30th, 2009, 12:32 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

... and don't ever use @@IDENTITY especially when triggers are involved. Use Scope_Identity() instead.
__________________
--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger to insert rows in Remote table anirbanbasuz SQL Language 1 August 25th, 2006 06:02 AM
insert,update trigger rolle SQL Server 2000 3 September 29th, 2005 08:41 PM
Help With INSERT + UPDATE Trigger HenryE SQL Server 2000 1 December 11th, 2003 06:26 PM
Insert Update Trigger mstuart60 SQL Server 2000 10 September 30th, 2003 06:54 AM
Update, insert and delete Trigger khautinh SQL Server 2000 2 September 17th, 2003 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.