196

Can anyone tell me where is the mistake in the following query

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
};

I get the following errors:

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 '{'.
1

9 Answers 9

218

You need to remove the brackets

ALTER TABLE Countries
ADD  
HasPhotoInReadyStorage  bit,
 HasPhotoInWorkStorage  bit,
 HasPhotoInMaterialStorage bit,
 HasText  bit;
Sign up to request clarification or add additional context in comments.

1 Comment

And to drop multiple columns: ALTER TABLE MyTable DROP COLUMN MyCol1, MyCol2, MyCol3
180

Take out the parentheses and the curly braces, neither are required when adding columns.

1 Comment

Also check your commas, looks like you're missing several for the second-to-last columns being added
45

this should work in 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 Comment

be careful not to include the GO - that is only used in MSSQL server mgmt studio but it is not a valid sql keyword.
11
Alter table Hotels 
Add  
{ 
 HasPhotoInReadyStorage  bit, 
 HasPhotoInWorkStorage  bit, 
 HasPhotoInMaterialStorage bit, 
 HasHotelPhotoInReadyStorage  bit, 
 HasHotelPhotoInWorkStorage  bit, 
 HasHotelPhotoInMaterialStorage bit, 
 HasReporterData  bit, 
 HasMovieInReadyStorage  bit, 
 HasMovieInWorkStorage  bit, 
 HasMovieInMaterialStorage bit 
}; 

Above you are using {, }.

Also, you are missing commas:

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

You need to remove the brackets and make sure all columns have a comma where necessary.

Comments

10

Can with default value (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

Comments

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

1 Comment

Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". We make an effort here to be a resource for knowledge.
1

Extending the codingbadger's answer to assign a default value

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;

Comments

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

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

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



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

...

in PostgreSQL at 2025

1 Comment

The question has a tag for SQL Server and your answer provides a solution for PostgreSQL. In this case there is no difference afaik, but you should pay attention in the future to avoid issue with different dialects
-2

This one worked for me

ALTER TABLE table_name
ADD column1 column1_definition;
ADD column2 column2_definition;
ADD column3 column3_definition;
...
ADD column columnn_definition;

2 Comments

Not in SQL Server though.
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.