Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have table and records in it.
When ever I update any field in table, I want automatically to update 1 particular column.
Eg.- When ever I update employee details,
I want to update datetime column so that i will come to know that on this date and time it is updated.
Can default constraint can do it.
Kindly suggest and guide.

Yes. Default constraints is enough for you. Just assign getdate() as default constraint for your record create/update track datetime column.
Share this answer

Try like this
ALTER TABLE Customers ADD CONSTRAINT DF_Customers_updDate 

Share this answer
Arunprasath Natarajan 25-Feb-13 5:25am    
It does not work.
gvprabu 25-Feb-13 5:28am    
If any Records have NULL in your table..?
Arunprasath Natarajan 25-Feb-13 12:16pm    
Yes, My Datetime column is NULL. When it is null it wont work?
gvprabu 26-Feb-13 3:31am    
So you have to Update Some Default value for All NULL Values. Then Make that column as NOT NULL and try this.
If Solution 1 and 2 dont works then try doing following things.

Every Time you Insert or Update write function "GetDate()" with the respective column.
Share this answer
Arunprasath Natarajan 25-Feb-13 12:27pm    
But it works when Insert query is executed.
MalwareTrojan 25-Feb-13 23:33pm    
it ll also work with UPDATE TableName Set Col_Name=GetDate() Where Cond.

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