这是 sp_rename 函数或 sql server 本身的问题吗? [英] is this a problem in the sp_rename function or sql server itself?

查看:21
本文介绍了这是 sp_rename 函数或 sql server 本身的问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重命名列名时,列名中包含方括号,我认为这是一个错误,这是一个示例代码片段,

While renaming the column name, the square bracket is included in the column name, which I think is a bug, Here is a sample code snippet,

 create table [TestTable]

(TestColumnName nvarchar(30))

select TestColumnName from TestTable

sp_rename '[TestTable].[TestColumnName]', '[RenamedColumnName]', 'Column'

select [RenamedColumnName] from TestTable -- does not work "Invalid column name 'RenamedColumnName'."

select RenamedColumnName from TestTable -- does not work "Invalid column name 'RenamedColumnName'."

select * from [TestTable]  -- works fine!!!

这里的错误是列重命名包含方括号,我发现this 表示第一个字符必须是以下字符之一",但是[" 似乎未包含在列表中,sp_rename 或 sql server 本身有问题吗?,因为它允许更改以方括号开头的列名.

The bug here is that the column rename includes the square brackets, I found this which says that the "first character must be one of the following", but "[" does not seem be included in the list, is there a problem with sp_rename or sql server itself?, as it allows alteration of column name to start with a square bracket.

推荐答案

您代码中的列已重命名为实际包含 [] 的列 - 要查询此列,您必须使用

The column in your code has been renamed to one that actually includes [] - to query this column you'll have to use

SELECT [[RenamedColumnName]]] FROM TestTable

] 是一个分隔标识符,因此您必须对其进行转义.对于 ],这意味着名称中使用的每个额外的 ].

] is a delimited identifier, so you have to escape it. For ], this means an additional ] for each one used in the name.

这篇关于这是 sp_rename 函数或 sql server 本身的问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆