How to change 2 or more columns at the same time in Sql Server 2014? (ALTER TABLE/ALTER COLUMN)

Asked

Viewed 1,343 times

2

How do I change 3 columns at the same time in the SQL SERVER table?

I want to change the COLLATION, but it could be something else.

I tried to:

ALTER TABLE dbo.SIX_POSTO
ALTER COLUMN VIS_DS VARCHAR(200) COLLATE Latin1_General_CI_AI NOT NULL,
ALTER COLUMN VIS_DS_OBSERVACAO VARCHAR(200) COLLATE Latin1_General_CI_AI 
NULL,
ALTER COLUMN VIS_DS_ENDERECO VARCHAR(500) COLLATE Latin1_General_CI_AI 
NULL

I tried too:

ALTER TABLE dbo.SIX_POSTO
ALTER COLUMN VIS_DS VARCHAR(200) COLLATE Latin1_General_CI_AI NOT NULL,
COLUMN VIS_DS_OBSERVACAO VARCHAR(200) COLLATE Latin1_General_CI_AI NULL,
COLUMN VIS_DS_ENDERECO VARCHAR(500) COLLATE Latin1_General_CI_AI NULL

And also:

ALTER TABLE dbo.SIX_POSTO
ALTER COLUMN VIS_DS VARCHAR(200) COLLATE Latin1_General_CI_AI NOT NULL,
VIS_DS_OBSERVACAO VARCHAR(200) COLLATE Latin1_General_CI_AI NULL,
VIS_DS_ENDERECO VARCHAR(500) COLLATE Latin1_General_CI_AI NULL

But that’s the only way it works:

ALTER TABLE dbo.SIX_POSTO
ALTER COLUMN VIS_DS VARCHAR(200) COLLATE Latin1_General_CI_AI NOT NULL
ALTER TABLE dbo.SIX_POSTO 
ALTER COLUMN VIS_DS_OBSERVACAO VARCHAR(200) COLLATE Latin1_General_CI_AI 
NULL
ALTER TABLE dbo.SIX_POSTO 
ALTER COLUMN VIS_DS_ENDERECO VARCHAR(500) COLLATE Latin1_General_CI_AI 
NULL

For each ALTER TABLE there can only be one ALTER COLUMN?

1 answer

4


You can do more than one command to add ADD or remove DROP COLUMN, but cannot stop the ALTER COLUMN. The command ALTER TABLE does not allow you to make more than one ALTER COLUMN, that is, you will need to make a ALTER TABLE for each column change that has to be made.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.