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 2nd, 2006, 03:03 PM
jnt jnt is offline
Registered User
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help w/create trigger by an insert operation

This is my scenerio,

In my procedure MOVIE_RENT_SP that is contained in the package MM_RENTALS_PKG an INSERT statement that inserts a row of data into MM_RENTAL table is followed by an UPDATE to MM_MOVIE that decreases by one the MOVIE_QTY value for the movie that is being rented. So, if I could assure that new rows always would be inserted into MM_RENTAL table by calling the MOVIE_RENT_SP everything would be fine. However, nothing prevents the users who have access to the MM_RENTAL table from just executing an INSERT statement from SQL*Plus or iSQL*Plus window. In such case, a new rental record is created without adjusting the available MOVIE_QTY value. I want to resolve this issue by making sure that MM_MOVIE table is automatically updated each time a new row of data is inserted into MM_RENTAL table.

Thus I need to create a trigger that is triggered by an INSERT operation on table MM_RENTAL. The trigger should update table MM_MOVIE by subtracting one from the value of MOVIE_QTY in the row that has the same MOVIE_ID as the new row in the MM_RENTAL table.

Anybody can help me with this?

Thanks alot
 
Old December 2nd, 2006, 08:09 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

First, you do realize that you posted a distinctly Oracle question on an SQL Server forum, don't you? The way triggers are handled in the two RDBMS's are quite different from one another.

That, not with standing, please post the portion of the code that decrements the Movie_Qty column of MM_Movie table so that we might glean such things as what the Primary Key, etc, might be from the code.

--Jeff Moden
 
Old December 14th, 2006, 07:31 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you an Oracle familar person that wants to find out how to do the equivalent in MS-SQL or did you just post in the MS-SQL room when you ment to post in the Oracle room?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Trigger debbiecoates SQL Server 2000 3 December 24th, 2007 08:00 AM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
Insert Trigger Arsi SQL Server 2000 2 February 25th, 2005 05:41 PM
Help With INSERT + UPDATE Trigger HenryE SQL Server 2000 1 December 11th, 2003 06:26 PM
Create Insert Trigger byron SQL Server 2000 6 November 19th, 2003 11:30 AM





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