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.

1

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry - but the second statement is not valid T-SQL code - you cannot define a default constraint using a SET DEFAULT clause....
You are correct, I was looking at the document given in the question, which seems to be incorrect. I fixed my answer. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.