I need to ALTER
the data types of several columns in a table.
For a single column, the following works fine:
ALTER TABLE tblcommodityOHLC
ALTER COLUMN
CC_CommodityContractID NUMERIC(18,0)
But how do I alter multiple columns in one statement? The following does not work:
ALTER TABLE tblcommodityOHLC
ALTER COLUMN
CC_CommodityContractID NUMERIC(18,0),
CM_CommodityID NUMERIC(18,0)
This is not possible. You will need to do this one by one.
You could create a Temporary Table with your modified columns in, copy the data across, drop your original table and rename your Temporary Table to your original name.
If you do the changes in management studio and generate scripts it makes a new table and inserts the old data into that with the changed data types. Here is a small example changing two column’s data types
As others have answered, you need multiple ALTER TABLE statements. Try:
etc.
Doing multiple ALTER COLUMN actions inside a single ALTER TABLE statement is not possible.
See the ALTER TABLE syntax here:
http://msdn.microsoft.com/en-US/library/ms190273.aspx
You can do multiple ADD or multiple DROP COLUMN, but just one ALTER COLUMN.
If i understood your question correctly you can add multiple columns in a table by using below mentioned query.
Query:
Put
ALTER COLUMN
statement inside a bracket, it should work.