1

The following syntax won't work:

ALTER TABLE MyCustomers 
ALTER COLUMN CompanyName SET DEFAULT 'A. Datum Corporation'

per url, http://msdn.microsoft.com/en-us/library/ms174123.aspx

Error message:

Incorrect syntax near the keyword 'set'.

What gives?

Thanks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user963063
  • 73
  • 1
  • 10
  • You need to check the correct documentation: http://msdn.microsoft.com/en-us/library/ms190273(v=sql.105).aspx. You linked to the Compact edition of SQL Server, but you're probably using the normal one... – MicSim May 16 '13 at 14:08

1 Answers1

1

Per this question: How to set a default value for an existing column

The following will work on SQL Server, and has the added benefit of naming the constraint:

ALTER TABLE MyCustomers 
ADD CONSTRAINT DF_SomeName DEFAULT 'A. Datum Corporation' FOR CompanyName;
Community
  • 1
  • 1
Duffmaster33
  • 1,160
  • 9
  • 16
  • Sorry - but the second statement is **not** valid T-SQL code - you **cannot** define a default constraint using a `SET DEFAULT` clause.... – marc_s May 16 '13 at 14:38
  • 1
    You are correct, I was looking at the document given in the question, which seems to be incorrect. I fixed my answer. Thank you. – Duffmaster33 May 16 '13 at 15:04