在关键字“Alter”附近修改列“不正确的语法”。

时间:2021-12-15 22:50:21

Aim:

目的:

Alter multiple columns from a newly created table

从新创建的表中修改多个列

I had the columns I wanted to modify in the code but have chopped it down to one for this example, there is nothing obvious I can see. I have an even number of brackets and so forth. Nothing is more than 200 characters long.

在代码中我想要修改的列,但是我把它删减到这个例子中,没有什么显而易见的。我有偶数个括号等等。没有什么比200个字符长。

Code:

代码:

DECLARE @tableALTER NVARCHAR(2500)

SET @tableALTER = ' 
(ALTER TABLE ' + @tableName + ' ALTER COLUMN [ID] VARCHAR(200))'
EXEC (@tableALTER) 

Using:

使用:

SQL Server Management Studio

SQL Server Management Studio

Error:

错误:

Incorrect syntax near the keyword 'ALTER'.
Incorrect syntax near ')'.

关键字“ALTER”附近的语法错误。不正确的语法)的附近。

Research includes:

研究包括:

How to change the data type of a column without dropping the column with query?

如何在不使用查询删除列的情况下更改列的数据类型?

1 个解决方案

#1


5  

How about removing the opening and closing parenthesis inside the string.. try this..

把弦里面的开括号和闭括号去掉怎么样试试这个. .

DECLARE @tableALTER NVARCHAR(2500)

SET @tableALTER = 'ALTER TABLE ' + @tableName + ' ALTER COLUMN [ID] VARCHAR(200)'
EXEC (@tableALTER)

#1


5  

How about removing the opening and closing parenthesis inside the string.. try this..

把弦里面的开括号和闭括号去掉怎么样试试这个. .

DECLARE @tableALTER NVARCHAR(2500)

SET @tableALTER = 'ALTER TABLE ' + @tableName + ' ALTER COLUMN [ID] VARCHAR(200)'
EXEC (@tableALTER)