开发者

Using a Default Value on Null Entry in Sybase

Good morning,

I have a question regarding default values and NULL values in Sybase ASE 12. To make a long story short: I have inherited a very old Sybase database as well as the PowerBuilder front end that sits on top of it. One of the tables in question contains several columns that have default values as well as the not null constraint. Thus, whenever no value (note: not a NULL value) is supplied, PowerBuilder creates the appropriate insert / update statement and simply does not pass a value for these empty fields, which are then automatically assigned the default value by the database. Gravy.

Now, the problem: It was decided to add auditing to the entire application via the front end (a bad idea, I know, but not my choice). A function was written to abstract the process of auditing but the problem arises from the fact that it sees no user entry as a NULL values and generates an insert statement into the audit table (also defined with the not null constraint), supplying the literal NULL for these empty开发者_Go百科 columns. Sybase then sees the literal NULL and, as you all know, treats the NULL as a value and not 'no entry'.

So the question: is it possible to default a NULL entry to a default values from the database side? I have considered triggers, but I am hoping I will get lucky and there will be some form of table-level construct that I can make use of.

Thank you for your time and consideration.

References:

A good example of the issue in question

http://www.sybaseteam.com/null-not-nothing-difference-between-null-nothing-sybase-t-390.html

See table 7-1, halfway down the page.

http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@ebt-link;pt=20741?target=%25N%15_19279_START_RESTART_N%25


I think you need to make your auditing function smarter. It should only log the columns the user changed. This is easy to determine with getitemstatus. You can loop through the columns using the form of getitemstatus that takes an integer column number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜