Re: trigger changing other table

From: Tom Moreau (tom_at_dont.spam.me.cips.ca)
Date: 07/31/04


Date: Sat, 31 Jul 2004 08:04:18 -0400

Check the value of @@ERROR and if non-zero, issue RAISERROR and ROLLBACK
TRAN.

-- 
    Tom
-------------------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON  Canada
www.pinnaclepublishing.com/sql
"Artur Z." <artekzx@o2.pl> wrote in message
news:ceemkm$okf$1@atlantis.news.tpi.pl...
thanks Tom and Ian, it worked
I have one more question:
how to throw an exception from trigger ?
for example when I decide in trigger that his delete operation should be
rolled back
thanks again
Artur
Uzytkownik "Tom Moreau" <tom@dont.spam.me.cips.ca> napisal w wiadomosci
news:#ZFbyMmdEHA.2384@TK2MSFTNGP09.phx.gbl...
> Yes, you can:
>
> CREATE TRIGGER trigger1 ON customer FOR DELETE AS
> UPDATE note
> SET
>     status = 2
> WHERE
>     customer_id in
> (
>     select
>         id
>     from
>     deleted
> )
>
>
>
> --
> Tom
>
> ---------------------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
>
> "Artur Z." <artekzx@o2.pl> wrote in message
> news:cee414$fhc$1@nemesis.news.tpi.pl...
> hello
>
> I'm here for the first time so hello everybody :)
>
> I came here to ask one question, because I have a problem with mssql
trigger
> creation:
> is it possible to create trigger on table A which modifies some records in
> table B ?
>
> I got the following error:
> "The column prefix 'deleted' does not match with a table name or alias
name
> used in query."
> when I try to create trigger:
> CREATE TRIGGER trigger1 ON customer FOR DELETE AS
> UPDATE note SET note.status = 2 WHERE note.customer_id = deleted.id
>
> is there any solution of this problem ?
>
> thanks in advance
>
> Artur
>
>


Relevant Pages

  • Re: Trigger Question
    ... Pro SQL Server 2000 Database Design - ... I just decided that if my trigger for delete was ... >> SQL Server MVP ... >>> UPDATE OrderDetail ...
    (microsoft.public.sqlserver.programming)
  • Re: Question: Triggers
    ... Shelling out to the OS is not a quick thing to do inside a trigger. ... Tibor Karaszi, SQL Server MVP ... I have a VB.NET application which searches for the existence of these ...
    (microsoft.public.sqlserver.server)
  • Re: Records not inserting...
    ... > I am totally new to SQL server. ... However, in a trigger, would I be ... test the effects of certain data modifications and to set conditions for ... UPDATE statements. ...
    (microsoft.public.sqlserver.odbc)
  • Re: Help for an Oracle Newbie
    ... application I wrote using SQL Server ported over to Oracle. ... Obviously there are several built in data types in SQL Server that do ... Of course I had to use a different name for the trigger under each ...
    (comp.databases.oracle.server)
  • Re: TRIGGER (AFTER INSERT) and Store Procedure ... insert failed !
    ... >into SQL server, the record exist anyway! ... >If you refresh the data you will see the record... ... it gets refreshed after trigger excecution automatically. ... I don't know your monitoring system, but I guess that removing the result ...
    (microsoft.public.sqlserver.programming)

Quantcast