Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 DEFAULT value for columns

Author  Topic 

ujjaval
Posting Yak Master

108 Posts

Posted - 2006-01-04 : 21:54:35
I have already tables created. Now, I want to specify Default values for each column using SQL. How can I do that? I tried using

alter table [dbo].[table] alter column testColumn int Default 5

it gave error at DEFAULT keyword. But I wonder how to use DEFAULT keyword for this.

or is there any other way?

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2006-01-04 : 22:09:28
I don't think you can add a default using the alter table/alter column command (but I could be wrong). Why not change the default through Enterprise Manager? It allows you (probably drops and recreates the column in the background)

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-04 : 22:14:04
You can't alter a column and set a default.
From SQL Server Books On Line
quote:
The altered column cannot be associated with a default, except that changing the length, precision, or scale of a column is allowed if the data type is not changed.

Use Enterprise Manager to do this. Right Click on the table and choose Design Table. Input the default value there.

-----------------
[KH]

2006 a new beginning
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-04 : 22:15:12
>> (probably drops and recreates the column in the background)
hmmm.. was wondering how EM does this.

-----------------
[KH]

2006 a new beginning
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2006-01-04 : 22:16:58
Are you guys on crack or just hung over from New Year?


alter table Mytable add constraint DF_X default (1) for MyColumn


DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2006-01-04 : 22:17:54
there - see! I told you I could be wrong

thanks dave

--
Design is NOT Intelligent science.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-04 : 22:38:47
>> Are you guys on crack or just hung over from New Year?


-----------------
[KH]

2006 a new beginning
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2006-01-04 : 22:46:07
speak for yourself KH, I'm on crack...

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2006-01-04 : 23:00:06
>> Design is NOT Intelligent science.

LOL Rob!

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2006-01-04 : 23:02:32
yeah, at least i'm good at something (sure dang well isn't these computery-thingammy-bobs)

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

ujjaval
Posting Yak Master

108 Posts

Posted - 2006-01-04 : 23:03:56
lol.. mate Design is Art.
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2006-01-04 : 23:07:29
now dave, 'e's orl 'art

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -