开发者

SQL Script Gone Wrong Need Help Recovering '[' character in column names causing problems [duplicate]

This question already has answ开发者_运维技巧ers here: How to rename something in SQL Server that has square brackets in the name? (5 answers) Closed 8 years ago.

used a script to rename a column which has caused a problem...

sp_RENAME 'products.isvalid' , '[_is_valid_system]', 'COLUMN'

Now I have a column name with square brackets in, and I can't access the column to resolve the problem.

Column Name:

[_is_valid_system]

An attempt to repair the issue like so fails because of the special characters in the command:

sp_RENAME 'products.[_is_valid_system]' , '_is_valid_system', 'COLUMN'

Any way of escaping these characters?

Even if I can just select from the column that will be good enough, but the following obviously does not work because of the special meaning of squared brackets in SQL server.

select [is_valid_system] from products


Try

sp_RENAME 'products."[_is_valid_system]"' , '_is_valid_system', 'COLUMN'


If SET QUOTED_IDENTIFIER is ON (should be default), try this

EXEC sp_RENAME 'products."[_is_valid_system]"' , '_is_valid_system', 'COLUMN'

FYI, you can use this too to query

SELECT "[is_valid_system]" FROM products
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜