Alter table add multiple columns ms sql

Sql Server-2005

Sql Server-2005 Problem Overview


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

Sql Server-2005 Solutions


Solution 1 - Sql Server-2005

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

Solution 2 - Sql Server-2005

You need to remove the brackets

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

Solution 3 - Sql Server-2005

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

Solution 4 - Sql Server-2005

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.

Solution 5 - Sql Server-2005

Can with defaulth 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

Solution 6 - Sql Server-2005

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser278618View Question on Stackoverflow
Solution 1 - Sql Server-2005Philip KelleyView Answer on Stackoverflow
Solution 2 - Sql Server-2005codingbadgerView Answer on Stackoverflow
Solution 3 - Sql Server-2005StefanoView Answer on Stackoverflow
Solution 4 - Sql Server-2005Neil KnightView Answer on Stackoverflow
Solution 5 - Sql Server-2005VolkanCetinkayaView Answer on Stackoverflow
Solution 6 - Sql Server-2005wagoView Answer on Stackoverflow