|
Home > Archive > SQL Anywhere database > April 2005 > triggers
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]
|
|
| Eric Verhorstert 2005-04-13, 3:23 am |
| We are using the ASA 7.0.4.3519 and have never used triggers before.
If in a certain table a record is inserted, deleted or certain columns
are updated we would like to copy the id of that record to another table.
We think the best way of doing that is to develop a trigger. Looking at
triggers we see a InsertTrigger, Beforeinserttrigger,
Afterinserttrigeer, insertproc, beforeinsertproc, afterinsertproc. The
same number of triggers are available for delete and update.
Can someone give an example how to copy the id to an other table when a
record is inserted, updated (certain comlum), or deleted?
| |
| Dmitri 2005-04-13, 3:23 am |
| Eric Verhorstert wrote:
> Can someone give an example how to copy the id to an other table when a
> record is inserted, updated (certain comlum), or deleted?
Here is least easy one - trigger that fires after update of mycolumn1
and mycolumn2 of the DBA.Mytable. Old values for mycolumn1 and mycolumn2
are stored in the dba.Mytable_log.
--------------------------------------------------------------
create trigger dba. Mytable_after_update
_trigger after update of
mycolumn1, mycolumn2 order 1 on DBA.Mytable
referencing old as deleted new as inserted
for each row
begin
insert into dba.Mytable_log (id, mycolumn1, mycolumn2)
values (inserted.id, deleted.mycolumn1, deleted.mycolumn2)
end
--------------------------------------------------------------
Dmitri.
|
|
|
|
|