views:

33

answers:

4

I have a sybase 15 DB and for one of my tables, I want to make a column default to the current date/time of the row insert. Is this possible?

In a sybase text, the following is said:

ALTER TABLE sales_order MODIFY order_date DEFAULT CURRENT DATE

On my DB this dosn't do anything ,as CURRENT DATE is not recognized.

A: 

Try using getDate() instead

GôTô
it says I need a Constant, constant expression, or variable after default.
jonjonjonjuice
That's surprising, I'm pretty sure I used it (for a table definition), like written here http://vista.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_getdate Unless you are not using Sybase ASE?
GôTô
A: 

using getDate() is a valid solution, you must have had a syntax error. Try it like this:

create table test_tbl ( date_data DATETIME default getDate() NOT NULL )

konnykonzzz123
A: 

... DEFAULT GETDATE() is correct. the case is irrelevant; mixed case may indicate a Java method, but it is a straight TSQL Function. Please post the exact error msg if you want further assistance.

Also, the ALTER TABLE method sets the Default for future INSERTS; if you want the existing data changed, you need to UPDATE (good for small tables) or unload/reload the table (demanded for the large).

Watch the NULL/NOT NULL: you do not want to change that without understanding. Again, the existing/future issue needs address. NOT NULL prevents NULL being explicitly passed as an INSERT VALUE.

PerformanceDBA
A: 

CURRENT_DATE is a SQL standard that isn't universally adopted. As noted elsewhere the getdate() T-SQL function should be used instead.

Rawheiser