is this a problem in the sp_rename function or sql server itself ?
- by user81967
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.