2010-03-26 65 views
110

誰能告訴我哪裏是在下面的查詢修改表中添加多列MS SQL

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 '{'. 
+0

的可能的複製[如何將多個列添加到SQL表並在其中的一個添加默認約束?](http://stackoverflow.com/questions/15184939/how-to-add-multiple-columns-to-sql -table-and-add-default-constraint-on-one-th) – 2016-08-10 07:24:30

回答

140

取出圓括號和花括號,添加列時都不需要。

+7

還檢查你的逗號,看起來像你錯過了幾個倒數第二到最後一列 – 2010-03-26 13:51:34

8
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); 

您需要刪除括號,並確保所有列都需要一個逗號的位置。

+0

爲什麼'('它給出了一個錯誤! – Adaptabi 2015-11-04 15:18:52

109

您需要刪除括號

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

這應該在工作的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

+1

它沒有添加列,只是ALTER TABLE國家添加HasPhotoInReadyStorage ... – jorgebg 2012-11-22 14:22:09

+1

@jorgebg感謝您抽出時間來糾正我 – Stefano 2013-03-07 13:23:10

+1

注意不要包含GO - 僅用於MSSQL服務器mgmt studio,但它不是有效的sql關鍵字。 – increddibelly 2016-02-09 08:55:41

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

請編輯更多信息。僅限代碼和「嘗試這個」的答案是不鼓勵的,因爲它們不包含可搜索的內容,也不解釋爲什麼有人應該「嘗試這個」。我們在這裏努力成爲知識的資源。 – 2016-07-08 13:56:30