RE: Trigger is not working when I test
From: Alejandro Mesa (AlejandroMesa_at_discussions.microsoft.com)
Date: 10/11/04
- Next message: Aaron [SQL Server MVP]: "Re: Select Top 100 Distinct"
- Previous message: Gridlock: "RE: Creating Views from Tables with identical column names"
- In reply to: DCSLICK: "Trigger is not working when I test"
- Next in thread: DCSLICK: "RE: Trigger is not working when I test"
- Reply: DCSLICK: "RE: Trigger is not working when I test"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 11 Oct 2004 12:23:16 -0700
This is from BOL.
deleted and inserted are logical (conceptual) tables. They are structurally
similar to the table on which the trigger is defined, that is, the table on
which the user action is attempted, and hold the old values or new values of
the rows that may be changed by the user action. For example, to retrieve all
values in the deleted table, use:
SELECT *
FROM deleted
**************************
In your case, the table inserted has same structure as table
video_collection.
CREATE TRIGGER CheckStock ON [video_collection]
FOR UPDATE
AS
IF EXISTS (SELECT * FROM inserted WHERE stock_on_hand < 0)
BEGIN
RAISERROR('Can not oversell products.', 16, 1)
RAISERROR('Transaction has been canceled.', 16, 1)
ROLLBACK
END
AMB
"DCSLICK" wrote:
> I was told that I need to add a business rule as one of the triggers that I
> am creating.
> In my program I have to write a trigger for
> insert, update on a database. For example If you see
> studentAge.inserted is <= 20 then rollback the insert
> with a error message else you can commit the insert or
> update.
>
> So for my trigger I created the following for my db.
>
> CREATE TRIGGER CheckStock ON [video_collection]
> FOR UPDATE
> AS
> IF EXISTS (SELECT * FROM stock_on_hand.inserted WHERE stock_on_hand < 0)
> BEGIN
> RAISERROR('Can not oversell products.', 16, 1)
> RAISERROR('Transaction has been canceled.', 16, 1)
> ROLLBACK
> END
>
> When testing I get an error message "invalid object name
> 'stock_on_hand.inserted'
>
>
> What am I doing wrong??
>
> TIA
>
- Next message: Aaron [SQL Server MVP]: "Re: Select Top 100 Distinct"
- Previous message: Gridlock: "RE: Creating Views from Tables with identical column names"
- In reply to: DCSLICK: "Trigger is not working when I test"
- Next in thread: DCSLICK: "RE: Trigger is not working when I test"
- Reply: DCSLICK: "RE: Trigger is not working when I test"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|