Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

database - Sybase ASE 15.7: Create Trigger such that before inserting I want to modify row being inserted

I am using Sybase ASE 15.7. I wish to create trigger before insert such that before inserting, I want to modify some fields in the inserted row.

Please help Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From a trigger perspective you have a couple options:

  • for insert trigger; must be defined against the base table; this trigger will fire after the data has been inserted to the table; the trigger would be coded to perform updates against the base table of the newly inserted row
  • instead of trigger; must be defined against a view (the view would be defined against the base table); you would perform your insert against the view which would cause the instead of trigger to fire; the trigger would be coded to copy/manipulate the data from the inserted pseudo-table and write the final data set into the base table

See create trigger for more details.


Another option would be to write a stored procedure that does all of the pre-insert changes; instead of inserting directly to the base table you would call the stored proc (passing in all of the column values as input parameters). [granted, less than ideal]

'course one other option would be to have the application perform the pre-insert checks and edits before inserting the final data set to the base table.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...