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.
| Author |
Topic |
|
DavidD
Yak Posting Veteran
73 Posts |
Posted - 2003-07-28 : 19:49:51
|
Hi all, I am trying to alter a column to add a default definition to it using the following syntaxalter table MyTablealter column MyColumn int default 0 I keep getting the error 'incorrect syntax near the keyword default' I can perform this operation using a default object, but according to BOL this is a legacy technique and the technique I am using should work fine - it does in the create table statement. Does anyone know what the story is?Thanks in advanceDavid |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-07-28 : 19:53:14
|
| ALTER TABLE Table1 ADD CONSTRAINT DF_Table1_MyColumn DEFAULT 0 FOR MyColumnTara |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-07-28 : 19:53:15
|
| Try:ALTER TABLE MyTable ALTER COLUMN MyColumn int DEFAULT(0) |
 |
|
|
DavidD
Yak Posting Veteran
73 Posts |
Posted - 2003-07-28 : 20:55:55
|
| Hi Rob + Tara, Thanks for your replies, but Tara - your technique uses the default object I mentioned I am trying to avoid using, according to BOL it is a legacy technique, but it seems to be the only one I can get to work. Rob - I get the same error as previously with your syntax. Does that command work for you? I am on SQL 2000 with SP3.RegardsDavid |
 |
|
|
shsmonteiro
Constraint Violating Yak Guru
290 Posts |
Posted - 2003-07-29 : 00:13:01
|
Hi David,Tara's syntax is the only one supported by SQL Server. But you don't need to name the default or even specify the constraint word. That is you can write ALTER TABLE Table1 ADD CONSTRAINTDF_Table1_MyColumn DEFAULT 0 FOR MyColumn or [code]ALTER TABLE Table1 ADD DEFAULT 0 FOR MyColumn[/0]Sérgio |
 |
|
|
DavidD
Yak Posting Veteran
73 Posts |
Posted - 2003-07-29 : 00:50:31
|
| Thanks Sergio |
 |
|
|
|
|
|