Friday, February 24, 2012

How to add a default to existing column in T-SQL?

Please help me with T-SQL sytax for adding a default constraint to existing
column. Books Online do not help at all.
Thanks!
Leon Shargorodsky
Leon,
alter table <table_name>
add constraint <constraint_name> DEFAULT (<expression>) for <column_name>
but it will not affect existing records
Thanks
Oleg
Message posted via http://www.sqlmonster.com
|||Of course, you can fix existing rows with a simple update statement (
although it may take a while for a large table. ) .
The add default statement should run very quickly however.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Leon Shargorodsky" <LeonShargorodsky@.discussions.microsoft.com> wrote in
message news:68C5CD27-98EF-42B0-B025-12881DCBAA42@.microsoft.com...
> Please help me with T-SQL sytax for adding a default constraint to
> existing
> column. Books Online do not help at all.
> Thanks!
> Leon Shargorodsky

No comments:

Post a Comment