MSSQL: renaming a table fails

igitur's profile image igitur posted 9 years ago in General Permalink
Hi, when renaming a table, invalid SQL is executed.

Example: renaming dbo.HedgingBond to dbo.HedgingInstrument:

EXEC sp_rename "dbo"."HedgingBond", "HedgingInstrument";


The correct syntax is:
EXEC sp_rename "dbo.HedgingBond", "HedgingInstrument";
igitur's profile image igitur posted 9 years ago Permalink
Good description on http://blog.sqlauthority.com/2008/08/26/sql-server-how-to-rename-a-column-name-or-table-name/
igitur's profile image igitur posted 9 years ago Permalink
Also, renaming an existing column in a table in MS SQL should be as such:

EXEC sp_rename "CalculationHedgingInstruments.HedgingBondCode", "HedgingInstrumentCode", 'COLUMN';
Code modification/commit from ansgarbecker, 9 years ago, revision 9.2.0.4954
MSSQL: Prefer "schema.table" quoting over "schema"."table". See http://www.heidisql.com/forum.php?t=18476
ansgar's profile image ansgar posted 9 years ago Permalink
Done in r4954.
igitur's profile image igitur posted 8 years ago Permalink

This is a good example of an issue that can be marked as fixed. Refer to issue 21940 .

Please login to leave a reply, or register at first.