Home > Archive > SQL Anywhere database > July 2005 > What can I do in a AFTER DELETE trigger?=









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author What can I do in a AFTER DELETE trigger?=
Martin Baur

2005-07-30, 8:23 pm

Hi there

I have a BEFORE DELETE trigger on some table to check whether deletion can begin.

If it can begin, I want to copy the record being deleted to a log table if it satisfies some condition which requires a join to examine.

So can I still join the record being deleted with other tables in a AFTER DELETE trigger on that table? Or can I only access the record being deleted ONLY in the dels.*?

Example what I want to achieve:

---
ALTER TRIGGER " Move_to_Ticket_Retur
ns" AFTER DELETE
ORDER 1 ON "DBA"."TICKET"
REFERENCING OLD AS dels
FOR EACH ROW
BEGIN
if (select TICKET_CONTROLLER_ID

from dba.SEAT_RESERVATIONS as sr
inner join dba.TICKET as t on t.TICKET_ID = sr.TICKET_ID
where t.TICKET_ID = dels.TICKET_ID) is not null then

insert into TICKET_RETURNS
(....)
select (..) from dba.TICKET where TICKET_ID = dels.TICKET_ID;

end if
END
---

Don't be angry if this is a silly question.

Thank you.


Martin Baur

MindPower.com, IT-Services
Paul Horan[TeamSybase]

2005-07-31, 3:23 am

You don't need to join it - you can reference any column from the row being deleted with the "dels" alias:

> if (select TICKET_CONTROLLER_ID

> from dba.SEAT_RESERVATIONS as sr
> where sr.TICKET_ID = dels.TICKET_ID) is not null then
>
> insert into TICKET_RETURNS
> (....)
> VALUES ( dels.TICKET_ID, dels.next_col, ... );


--
Paul Horan[TeamSybase]

"Martin Baur" <tinu@mindpower.com> wrote in message news:MPG. 1d5629136c5b0fbb9898
1f@forums.sybase.com...
> Hi there
>
> I have a BEFORE DELETE trigger on some table to check whether deletion can begin.
>
> If it can begin, I want to copy the record being deleted to a log table if it satisfies some condition which requires
> a join to examine.
>
> So can I still join the record being deleted with other tables in a AFTER DELETE trigger on that table? Or can I only
> access the record being deleted ONLY in the dels.*?
>
> Example what I want to achieve:
>
> ---
> ALTER TRIGGER " Move_to_Ticket_Retur
ns" AFTER DELETE
> ORDER 1 ON "DBA"."TICKET"
> REFERENCING OLD AS dels
> FOR EACH ROW
> BEGIN
> if (select TICKET_CONTROLLER_ID

> from dba.SEAT_RESERVATIONS as sr
> inner join dba.TICKET as t on t.TICKET_ID = sr.TICKET_ID
> where t.TICKET_ID = dels.TICKET_ID) is not null then
>
> insert into TICKET_RETURNS
> (....)
> select (..) from dba.TICKET where TICKET_ID = dels.TICKET_ID;
>
> end if
> END
> ---
>
> Don't be angry if this is a silly question.
>
> Thank you.
>
>
> Martin Baur
>
> MindPower.com, IT-Services



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com