July 26, 2010 at 1:50 pm
Hi,
I have an existing column defined as NVARCHAR(10) NULL with no CONSTRAINT to which I would like to add a DEFAULT CONSTRAINT. However the syntax below from BOL generates the following error:
BOL syntax:
ALTER TABLE MyCustomers ALTER COLUMN CompanyName SET DEFAULT 'A. Datum Corporation'
Error Msg:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'SET'.
Can anyone explain why the above ALTER STATEMENT errors out?
Thanks,
MCTS: BI 2008, MCITP: BI 2008
Stay Thirsty My Friends
July 26, 2010 at 2:33 pm
Try "Add Contraint" instead of "alter column":
ALTER TABLE MyTable ADD CONSTRAINT default_name DEFAULT 'my default value' FOR MyColumn;
July 26, 2010 at 9:39 pm
I believe the actual format is something like this:
ALTER TABLE Table1
ADD CONSTRAINT Cont_XYZ DEFAULT('hello') for Column1
Fraggle
July 27, 2010 at 8:26 am
You are right, Fraggle. The syntax ALTER TABLE table_name ADD CONSTRAINT DF_constraint_name DEFAULT('hello') FOR column_name works perfectly. I was just wondering why the BOL syntax was giving that error.
Thanks
MCTS: BI 2008, MCITP: BI 2008
Stay Thirsty My Friends
July 27, 2010 at 8:50 am
I suspect you're looking at the BOL for the wrong version of SQL Server. I found the BOL you are referencing, but it is for SQL Server Compact: http://msdn.microsoft.com/en-us/library/ms174123(SQL.100).aspx. The BOL for SQL Server 2008 looks quite a bit different: http://msdn.microsoft.com/en-us/library/ms190273.aspx
--J
July 27, 2010 at 2:06 pm
You are right jvanderberg, it is the syntax for SQL Server Compact.
Thanks for taking a look.
MCTS: BI 2008, MCITP: BI 2008
Stay Thirsty My Friends
July 27, 2010 at 2:08 pm
No problem. I did the same thing, and thought the BOL was crazy. I wanted to know what was up too, so I did a little digging and realized I was looking at the wrong documenation.
July 27, 2010 at 2:27 pm
Wow, who would have thought that the Compact Ed would use different sytax for this. Crazy.
Fraggle.
July 27, 2010 at 4:38 pm
I know.
I have not used the Compact edition much but never knew there were differences in syntax...very interesting.
MCTS: BI 2008, MCITP: BI 2008
Stay Thirsty My Friends
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply