Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to apply current system date and time to two columns (created_date ,last_updated_date). How to use default constraint for this requirement?

thanks in advance.

What I have tried:

ALTER TABLE DOMAIN
ADD CONSTRAINT dt_1 DEFAULT GETDATE() FOR (CREATED_DATE,LAST_UPDT_DATE)
GO


gettging error msg like:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Posted
Updated 15-Feb-16 19:55pm
v2

Try this syntax:

SQL
ALTER TABLE TABLENAME
ADD CONSTRAINT CONSTRAINTNAME DEFAULT GETDATE() FOR COLUMNNAME
 
Share this answer
 
Comments
Member 10714689 16-Feb-16 2:07am    
thanks for the reply,
but I need to apply two date columns (created_date,updated_date), can't we apply to two columns at a time?
Try

SQL
ALTER TABLE DOMAIN
ADD CONSTRAINT dt_1 DEFAULT GETDATE() FOR CREATED_DATE
    , CONSTRAINT dt_2 DEFAULT GETDATE() FOR LAST_UPDT_DATE
GO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900