Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

triggers in Sybase

Status
Not open for further replies.

peglin

IS-IT--Management
Jul 12, 2002
14
US
Hey guys,

I needed to know how to create a trigger in Sybase and if I am tracking old date and time how would I do that before it has been overwritten by a new time and date. I need to insert old date and time into a new table.

Thanks for your help.

peglin
 
hello,

try something like this...

---
if exists(select 1 from sysobjects where type = "TR" and name = "triggerName_upd")
drop trigger dbo.triggerName_upd
go

create trigger dbo.triggerName_upd
on dbo.tableName
for update
as

begin
insert newTableName
select tableName.primaryKeyColumnName, deleted.dateColumnName, inserted.dateColumnName
from tableName, deleted, inserted
where tableName.primaryKeyColumnName = inserted.primaryKeyColumnName
and tableName.primaryKeyColumnName = deleted.primaryKeyColumnNmae

if (select count(1)
from tableName, inserted
where tableName.primaryKeyColumnName = inserted.primaryKeyColumnName) > 1
begin
raiserror 20001 "ERROR: One primaryKeyColumnName can have only one dateColumnName!"
rollback
end
end
go
---

this trigger will insert your new table with the old and new dates based on your primary key before it updates the current table...

hth,
q.
 
I made the changes from what you sent me, but the Sybase gives me errors when I execute the script.


 
hello,

please note that this trigger is assuming that you already have the new table created in the database...

if you are running the trigger in isql... run the drop statement first...

then run the create trigger portion...

do you mind posting the sybase errors?

thanks,
q.
 
Hey Q,

I got the trigger to work. It is though differnt from what you had suggested. I don't have the code of the tirgger in front of me. I will post it here by tonight. Would you happen to know any good books for Powerbuilder 7/8 to start learning from?

Thank you for your help.
 
i need to create trigger and define raise error and call this error in power buider application..

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top