Friday, February 17, 2012

Effects of changing a table name

If I rename a table on my SQL Server 2005 database say from Carriers to
Partners, will it update the stored procedures that reference the old table
name "carriers" to the new "partners" name? I am talking about using the
rename function in the rename function in the micosoft SQL Server managment
studio program. Or will I have to edit my 1,351 stored procedures manually?
thanks!> If I rename a table on my SQL Server 2005 database say from Carriers to
> Partners, will it update the stored procedures that reference the old
> table name "carriers" to the new "partners" name?
No, SQL Server is not going to go and edit your code for you. It would be
hard enough to find all the places it is referenced in vanilla T-SQL (and
this would rely on a correct sysdepends, rather than deferred name
resolution), what about all the places where the table name could be
referenced dynamically (e.g. EXEC('SELECT * INTO t1 FROM Carriers', or
EXEC('SELECT * INTO t1 FROM Car'+'riers'), or EXEC('SELECT * FROM
'+@.TableName))? Even if you took your procedure code offline and did a
grep/replace, you're still not guaranteed to find every single location.

> I am talking about using the rename function in the rename function in the
> micosoft SQL Server managment studio program. Or will I have to edit my
> 1,351 stored procedures manually?
An alternative would be to create a synonym.
A

No comments:

Post a Comment