Removing [] around column in SQL Server 2005

Sree picture Sree · Apr 13, 2012 · Viewed 10.2k times · Source

when I was renaming the column in SQL Server, I accidentally inserted the square brackets around the column. The actual statement that I used was:

SP_RENAME 'customer.[EMPLOYEENAMES]', '[EMPLOYEENAME]', 'COLUMN'

But when I try to retrieve the data it just says and I even tried with out square brackets, it gives the same error

Invalid column name '[EMPLOYEENAME]'.

How should I remove the square brackets.

Answer

Nikola Markovinović picture Nikola Markovinović · Apr 13, 2012

This will restore order in your database:

EXEC SP_RENAME 'customer."[EmployeeName]"', 'EmployeeName','COLUMN'

You cannot use double brackets because it returns syntax error. Quotes circumvent this limitation.