Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a default value to an existing column

Status
Not open for further replies.

archwisp

Programmer
Feb 13, 2003
4
0
0
US
Hello everyone. I am in the middle of a huge database redesign and I was wondering if anyone knows of a way to set a default value to an existing column?

The colum in data-type DATETIME and I want to set the default of that column to getdate() without having to recreate the table and do a bunch of selecting back and forth to get it to work.

Any ideas would be greatly appreciated.

PS: The Microsoft Transact-SQL refrence doesnt have anything about this topic. I believe sp_bindefault only works with varchar variables? I also tried to seach this forum but apparently the search feature is not working. I got a 404 :)

Thanks a ton again.
 
Code:
ALTER TABLE MyTable
ADD CONSTRAINT MyDefault GetDate()
  FOR MyColumn

If you want to create the default constraint and replace the NULL values with the default, then this should do the trick:

Code:
ALTER TABLE MyTable
ADD CONSTRAINT MyDefault GetDate()
  FOR MyColumn WITH VALUES


--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
You are a savior man!
It was so simple. I tried so many different variations of that it was driving me nuts. Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top