Altertable 添加多个列 msql

谁能告诉我下面查询中的错误在哪里

ALTER TABLE Countries
ADD (
HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit,
HasText  bit);


ALTER TABLE Regions
ADD ( HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit
HasText  bit);


ALTER TABLE Provinces
ADD ( HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit
HasText  bit);




ALTER TABLE Cities
ADD ( HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit
HasText  bit);


Alter table Hotels
Add
{
HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit,
HasHotelPhotoInReadyStorage  bit,
HasHotelPhotoInWorkStorage  bit,
HasHotelPhotoInMaterialStorage bit,
HasReporterData  bit,
HasMovieInReadyStorage  bit,
HasMovieInWorkStorage  bit,
HasMovieInMaterialStorage bit
};

我得到以下错误:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 15
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 22
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 29
Incorrect syntax near '{'.
394714 次浏览
Alter table Hotels
Add
{
HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit,
HasHotelPhotoInReadyStorage  bit,
HasHotelPhotoInWorkStorage  bit,
HasHotelPhotoInMaterialStorage bit,
HasReporterData  bit,
HasMovieInReadyStorage  bit,
HasMovieInWorkStorage  bit,
HasMovieInMaterialStorage bit
};

你上面用的是{ ,}。

另外,你还漏掉了逗号:

ALTER TABLE Regions
ADD ( HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit <**** comma needed here
HasText  bit);

您需要删除括号,并确保所有列在必要的地方都有逗号。

除去括号和花括号,在添加列时两者都不需要。

您需要删除括号

ALTER TABLE Countries
ADD
HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit,
HasText  bit;

这应该在 T-SQL 中起作用

ALTER TABLE Countries  ADD
HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit,
HasText  bit GO

Http://msdn.microsoft.com/en-us/library/ms190273(sql.90).aspx

ALTER TABLE Regions
ADD ( HasPhotoInReadyStorage  bit,
HasPhotoInWorkStorage  bit,
HasPhotoInMaterialStorage bit *(Missing ,)*
HasText  bit);

可以使用默认值(T-SQL)

ALTER TABLE
Regions
ADD
HasPhotoInReadyStorage BIT NULL, --this column is nullable
HasPhotoInWorkStorage BIT NOT NULL, --this column is not nullable
HasPhotoInMaterialStorage BIT NOT NULL DEFAULT(0), --this column is not nullable and set default value is 0(zero)
HasPhotoInThingStorage BIT NOT NULL CONSTRAINT DF_HasPhotoInThingStorage DEFAULT(0) --this column is not nullable and set default value is 0(zero) with spesific constraint name
GO

扩展编码獾的答案以分配默认值

ALTER TABLE Countries
ADD
HasPhotoInReadyStorage bit DEFAULT 1 WITH VALUES,
HasPhotoInWorkStorage bit DEFAULT 0 WITH VALUES,
HasPhotoInMaterialStorage bit DEFAULT 0 WITH VALUES,
HasText bit DEFAULT 1 WITH VALUES;