| 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 5it 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" |
 |
|
|
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 Linequote: 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 |
 |
|
|
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 |
 |
|
|
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 DavidMIntelligent Design is NOT science.A front-end is something that tries to violate a back-end. |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2006-01-04 : 22:17:54
|
| there - see! I told you I could be wrongthanks dave--Design is NOT Intelligent science. |
 |
|
|
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 |
 |
|
|
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" |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2006-01-04 : 23:00:06
|
| >> Design is NOT Intelligent science.LOL Rob!DavidMIntelligent Design is NOT science.A front-end is something that tries to violate a back-end. |
 |
|
|
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" |
 |
|
|
ujjaval
Posting Yak Master
108 Posts |
Posted - 2006-01-04 : 23:03:56
|
| lol.. mate Design is Art. |
 |
|
|
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" |
 |
|
|
|