Wrox Programmer Forums
|
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 August 24th, 2005, 01:49 AM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trigger Error

Hi everyone,

I have one trigger to update or insert the new record into the new table but it seems doesn't work,

CREATE TRIGGER [TriggerWO] ON [dbo].[WO2]
FOR INSERT, UPDATE
AS
UPDATE [dbo].[WO2]
SET [dbo].[WO2] .[WO#] = i.[WO#]
FROM [dbo].[WO2] join inserted i
ON
 i.[WO#] = [dbo].[WO2].[WO#]

Anyone can help ?
Thanks

 
Old August 24th, 2005, 02:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Is there an error.. what is not working.. the code looks correct.
 
Old August 24th, 2005, 06:17 PM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't trigger to the WO2 table after i insert new record.
So i dont understand what's wrong with my code!!!!

 
Old August 24th, 2005, 11:19 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Your trigger is for and Insert or Update, so that's how it is designed, what are you expecting to happen?

 
Old August 24th, 2005, 11:26 PM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i want to do both, coz i read from the book and i just modify the code from there, so i thought this one will work. But it doesnt work ....

 
Old August 24th, 2005, 11:39 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

So are you saying that if you UPDATE or INSERT into the DO2 table, the trigger does not fire? If so, I will have to do some testing.

 
Old August 25th, 2005, 07:27 PM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes....i try so many time but it still doesn't fire the trigger when i insert new data into the table.

 
Old August 25th, 2005, 10:29 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   Let me ask, how do you know the trigger is not firing? If you INSERT and don't have a mathing record, nothing will update. The same holds true if you UPDATE with no matching record. Are you sure you have data in the tables that matches the criteria? For a test you can just do a print staement in your trigger to see if it is firing on an INSERT or UPDATE. I suggest you try that first to be sure the trigger is fired.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on Trigger arnabghosh SQL Server 2000 3 August 21st, 2008 02:07 AM
Trigger realgone_ SQL Language 4 January 27th, 2005 11:49 AM
Trigger Creation Syntax Error SniffenLik SQL Language 3 July 25th, 2004 12:28 PM
Retrive Error no or message from Trigger salman VB Databases Basics 0 May 5th, 2004 06:58 AM
Error about trigger Blueman137 Oracle 2 March 10th, 2004 08:53 PM





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