1

I want to add a new Column to an existing Table that has already Data in it. The Column should be NOT NULL. Because of that i want to set a Default Value. But when i do it throws the following exception: "Incorrect syntax near 'for'"

ALTER TABLE Semester ADD SIDNew uniqueidentifier NOT NULL 
CONSTRAINT DF_SIDNew DEFAULT '00000000-0000-0000-0000-000000000000' FOR SIDNew

I already had a look at How to set a default value for an existing column and Incorrect syntax near the keyword 'FOR' but none of them helped me.

2 Answers 2

4

Simply lose the part FOR SIDNew. You are adding a new column with a default constraint. You are not adding a new default constraint to an existing column.

Sign up to request clarification or add additional context in comments.

Comments

3

The FOR keyword is only required if you're adding default values to Azure SQL Data Warehouse or Parallel Data Warehouse. If you're using normal relational SQL Server (on-premise or Azure) then you can just write it without the FOR

ALTER TABLE Semester ADD SIDNew uniqueidentifier NOT NULL 
CONSTRAINT DF_SIDNew DEFAULT '00000000-0000-0000-0000-000000000000';

https://msdn.microsoft.com/en-gb/library/ms190273.aspx

Comments

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.