is this a problem in the sp_rename function or sql server itself ?

Posted by user81967 on Stack Overflow See other posts from Stack Overflow or by user81967
Published on 2010-03-29T12:05:04Z Indexed on 2010/03/29 12:13 UTC
Read the original article Hit count: 230

Filed under:
|

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!!!

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, can there be a problem with sp_rename or sql server itself, as it allows alteration of column name to start with a square bracket.

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about tsql