Home All Groups Group Topic Archive Search About

newbie tsql/column def'n: default values - SQL Server 2005

Author
22 Dec 2005 4:24 PM
Chris Smith
I have a table that has phone numbers, and a phone-type column. The phone
type is foreign-keyed into a phone type table, and the phone-types in both
tables are integers.

I want to change this to use the new UniqueValues data type.

In Management Studio I can create the new column easy enough. But how do I
get the new column to have a default value of NewID() ? I've checked the
books online, and they seem to hint that this is possible, but darned if I
can figure it out.

Any help in doing this would be greatly appreciated.

Tanks.

Author
22 Dec 2005 4:53 PM
Aaron Bertrand [SQL Server MVP]
ALTER TABLE [dbo].[table_name]
    ADD CONSTRAINT [constraint_name]
    DEFAULT (NEWID()) FOR [column_name]





"Chris Smith" <chris.sm***@shaw.ca> wrote in message
news:GqAqf.169553$Gd6.75706@pd7tw3no...
Show quote
>I have a table that has phone numbers, and a phone-type column. The phone
>type is foreign-keyed into a phone type table, and the phone-types in both
>tables are integers.
>
> I want to change this to use the new UniqueValues data type.
>
> In Management Studio I can create the new column easy enough. But how do I
> get the new column to have a default value of NewID() ? I've checked the
> books online, and they seem to hint that this is possible, but darned if I
> can figure it out.
>
> Any help in doing this would be greatly appreciated.
>
> Tanks.
>
Author
22 Dec 2005 5:20 PM
Chris Smith
Wow. So simple even an 8 year old could have figured it out.

Problem is, there's never an 8 year old around when you need one.

:-)

Thank you.


Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:evN5YfxBGHA.3452@TK2MSFTNGP10.phx.gbl...
> ALTER TABLE [dbo].[table_name]
>    ADD CONSTRAINT [constraint_name]
>    DEFAULT (NEWID()) FOR [column_name]
>
>
>
>
>
> "Chris Smith" <chris.sm***@shaw.ca> wrote in message
> news:GqAqf.169553$Gd6.75706@pd7tw3no...
>>I have a table that has phone numbers, and a phone-type column. The phone
>>type is foreign-keyed into a phone type table, and the phone-types in both
>>tables are integers.
>>
>> I want to change this to use the new UniqueValues data type.
>>
>> In Management Studio I can create the new column easy enough. But how do
>> I get the new column to have a default value of NewID() ? I've checked
>> the books online, and they seem to hint that this is possible, but darned
>> if I can figure it out.
>>
>> Any help in doing this would be greatly appreciated.
>>
>> Tanks.
>>
>
>

AddThis Social Bookmark Button