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 January 14th, 2005, 08:40 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default i have a problemdeling with triggers

problem discription:
i made a trigger (insted of update),an it works correctly, but if the updte statement matches more than one record an error appeared
ex: if i have products table,and i want to update the unitprice for the products which have Supplier id of 4 (ofcourse, many product my be supplied by one supplier).
all what i need from my trigger is: if the unit new price is less than the old one , the trigger puts the new in the audi table and rollback the transaction.
ANY ONE CAN HELP?????

 
Old January 16th, 2005, 03:50 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Post your trigger

here is an example

Code:
CREATE TRIGGER yourTriggerNameHere
ON yourTable
AFTER INSERT
AS
DELETE FROM yourTable
FROM yourTable
INNER JOIN inserted ON inserted.col = yourTable.col AND inserted.[col2] = yourTable.[col2]
WHERE inserted.col3 = 'value' AND yourTable.col3 <> 'value'

Notes:


1.A ROLLBACK in a trigger following a DELETE would also roll back the DELETE. It would (as intended) also rollback the initial insert that caused the trigger.
2.If this is SQL 2000, you could consider using an INSTEAD OF trigger, which, instead of having to delete the row(s) just inserted, could avoid inserting it to begin with.


Jaime E. Maccou





Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggers? odezzie Classic ASP Databases 1 March 28th, 2007 06:09 PM
Triggers mrookey SQL Server 2000 2 October 24th, 2006 07:11 AM
Triggers? prabodh_mishra Oracle 2 March 30th, 2006 05:51 AM
Triggers shahchi1 SQL Server 2000 1 November 1st, 2004 06:28 PM





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