I have a table with square brackets and a period in the table name like this:
[dbo].[mytable]
The brackets and dbo and period are all part of the unqualified table name (please don't ask me to explain how this mess happened).
I want to rename this table without brackets, periods, dbo, but I can't execute any SQL statements on it without getting errors.
I've tried the following:
Do the brackets have to be escaped? If so, how? I've tried enclosing them in brackets: [[] and []]. And I've tried doubling them: [[ and ]]. Nothing works.
I am using Aqua DataStudio 4.7 (similar to Enterprise Manager) to run queries.
[dbo].[mytable]
The brackets and dbo and period are all part of the unqualified table name (please don't ask me to explain how this mess happened).
I want to rename this table without brackets, periods, dbo, but I can't execute any SQL statements on it without getting errors.
I've tried the following:
Code:
sp_rename '[dbo].[my_table]', 'mytable'
ERROR: No item by the name of '[dbo].[my_table]' could be found in the current database 'mydatabase', given that @itemtype was input as '(null)'.
sp_rename '[[dbo].[my_table]]', 'mytable'
ERROR: Syntax error parsing SQL identifier '[[dbo].[my_table]]'.
sp_rename '[dbo].[[dbo].[my_table]]', 'mytable'
ERROR: Syntax error parsing SQL identifier '[[dbo].[my_table]]'.
Do the brackets have to be escaped? If so, how? I've tried enclosing them in brackets: [[] and []]. And I've tried doubling them: [[ and ]]. Nothing works.
I am using Aqua DataStudio 4.7 (similar to Enterprise Manager) to run queries.