问题描述
我想向其中已经有数据的现有表中添加一个新列.列应该不为空.因此,我想设置一个默认值.但是,当我这样做时,它会引发以下异常:'for'附近的语法不正确"
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
我已经看过如何设置现有列的默认值和关键字"FOR"附近的语法不正确,但没有一个对我有帮助.
I already had a look at How to set a default value for an existing columnand Incorrect syntax near the keyword 'FOR' but none of them helped me.
推荐答案
仅丢失部分FOR SIDNew
.您正在添加具有默认约束的新列.您没有在现有列中添加新的默认约束.
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.
这篇关于"for" SQL Server附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!