jonjonjonjuice
jonjonjonjuice

Reputation: 103

make a column in sybase default to the current date/time of row insertion

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 doesn't do anything, as CURRENT DATE is not recognized.

Upvotes: 3

Views: 25149

Answers (4)

konnykonzzz123
konnykonzzz123

Reputation: 91

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
)

Upvotes: 9

Rawheiser
Rawheiser

Reputation: 1228

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

Upvotes: 1

PerformanceDBA
PerformanceDBA

Reputation: 33818

... 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.

Upvotes: 2

GôTô
GôTô

Reputation: 8053

Try using getDate() instead

Upvotes: 3

Related Questions