更改表添加多列ms sql

use*_*618 132 sql-server-2005

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

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
};
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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 '{'.
Run Code Online (Sandbox Code Playgroud)

Phi*_*ley 158

取出括号和花括号,添加列时都不需要.

  • 还要检查你的逗号,看起来你错过了几个要添加的倒数第二列 (8认同)

cod*_*ger 136

您需要删除括号

ALTER TABLE Countries
ADD  
HasPhotoInReadyStorage  bit,
 HasPhotoInWorkStorage  bit,
 HasPhotoInMaterialStorage bit,
 HasText  bit;
Run Code Online (Sandbox Code Playgroud)


Ste*_*ano 36

这应该在T-SQL中工作

ALTER TABLE Countries  ADD
HasPhotoInReadyStorage  bit,  
HasPhotoInWorkStorage  bit,  
HasPhotoInMaterialStorage bit,  
HasText  bit GO
Run Code Online (Sandbox Code Playgroud)

http://msdn.microsoft.com/en-us/library/ms190273(SQL.90).aspx


Nei*_*ght 10

Alter table Hotels 
Add  
{ 
 HasPhotoInReadyStorage  bit, 
 HasPhotoInWorkStorage  bit, 
 HasPhotoInMaterialStorage bit, 
 HasHotelPhotoInReadyStorage  bit, 
 HasHotelPhotoInWorkStorage  bit, 
 HasHotelPhotoInMaterialStorage bit, 
 HasReporterData  bit, 
 HasMovieInReadyStorage  bit, 
 HasMovieInWorkStorage  bit, 
 HasMovieInMaterialStorage bit 
}; 
Run Code Online (Sandbox Code Playgroud)

上面你正在使用{,}.

此外,您缺少逗号:

ALTER TABLE Regions 
ADD ( HasPhotoInReadyStorage  bit, 
 HasPhotoInWorkStorage  bit, 
 HasPhotoInMaterialStorage bit <**** comma needed here
 HasText  bit); 
Run Code Online (Sandbox Code Playgroud)

您需要删除括号并确保所有列都在必要时使用逗号.


Vol*_*aya 6

可以使用默认值 (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 default value is false
GO
Run Code Online (Sandbox Code Playgroud)