is there a way in sybase ase15 to set a value of a column when the row is updated
Basically what i want is a last_modified_datestamp 开发者_运维知识库column which is set to the date when the row was either inserted or updated. i know mysql has it was wondering if sybase has an equivalent or do i need to add a trigger.
Thanks, Shaun
I don't know what the non-standard non-SQLs of the world do, but IEC/ISO/ANSI Standard SQL has had this feature from its date of acceptance as a standard.
It is a column (whatever you name it, eg. UpdatedDateTime) of TIMESTAMP DataType. It is automatically set by the server when the row is UPDATED or INSERTED, and cannot be circumvented in code.
A DEFAULT of GETDATE() (there is not "CURRENT DATE" in Sybase) is a completely different animal. If, and only if, the INSERT does not specify a value for that column, it defaults to the identified DEFAULT value, current datetime. Second, it does not get updated on an UPDATE command.
Now the reason I bother to tell you about the Non-SQLs of the world is, they do not use the Standard Requirement for TIMESTAMP, which is the Unix Epoch, they use some funny nonsense, and you won't get that funny nonsense in a standard-compliant SQL, you get the Standard treatment. You can access it (the normal way) using the TSEQUAL Function. To read the TIMESTAMP column directly, treat it as BINARY, as per the example.
I think this is what you're after
ALTER TABLE table_name
MODIFY date_column DEFAULT CURRENT DATE
精彩评论