 |
| 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
|
|
|
|

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

August 24th, 2005, 02:23 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Is there an error.. what is not working.. the code looks correct.
|
|

August 24th, 2005, 06:17 PM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It doesn't trigger to the WO2 table after i insert new record.
So i dont understand what's wrong with my code!!!!
|
|

August 24th, 2005, 11:19 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Your trigger is for and Insert or Update, so that's how it is designed, what are you expecting to happen?
|
|

August 24th, 2005, 11:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ....
|
|

August 24th, 2005, 11:39 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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.
|
|

August 25th, 2005, 07:27 PM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes....i try so many time but it still doesn't fire the trigger when i insert new data into the table.
|
|

August 25th, 2005, 10:29 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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.
|
|
 |