Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Change table name Expand / Collapse
Author
Message
Posted Thursday, January 10, 2013 6:56 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 416, Visits: 2,547
Hi All,

I know you can change table name using the sp_rename 'old_table_name', new_table_name', but I am more concerned about what effects it will have or what are the things I need to check before changing table name?

This is not in prod yet so, I would think it's best to change it now.

Can you share your experience.

Thanks,
SueTons.


Regards,
SQLisAwe5oMe.
Post #1405406
Posted Thursday, January 10, 2013 7:03 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:20 AM
Points: 5,231, Visits: 5,106
Any references to that table will break once the name is changed, so things like views, functions, procedures etc will need checking to see if they reference the table in anyway.

The sys.sql_modules table will be a very good place to start by quering the definition column for the table name in question.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1405411
Posted Thursday, January 10, 2013 7:07 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 416, Visits: 2,547
anthony.green (1/10/2013)
Any references to that table will break once the name is changed, so things like views, functions, procedures etc will need checking to see if they reference the table in anyway.

The sys.sql_modules table will be a very good place to start by quering the definition column for the table name in question.


So, you are saying I have change any references to this table (like views, functions, procedures etc) manually?

SueTons.


Regards,
SQLisAwe5oMe.
Post #1405416
Posted Thursday, January 10, 2013 7:11 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:20 AM
Points: 5,231, Visits: 5,106
Yes that is correct, any referencing objects need to be manually updated with the new table name, SQL wont do it for you.

It even gives you a warning once the rename has happened to detail this could break things.


Changing any part of an object name can break scripts and stored procedures.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1405420
Posted Thursday, January 10, 2013 7:13 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 416, Visits: 2,547
Thanks Anthony....appreciate your quick response.

SueTons.


Regards,
SQLisAwe5oMe.
Post #1405424
Posted Thursday, January 10, 2013 7:26 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 416, Visits: 2,547
[b]The sys.sql_modules table will be a very good place to start by quering the definition column for the table name in question.


Anthony, What exactly am I looking here(sys.sql_modules).

SueTons.


Regards,
SQLisAwe5oMe.
Post #1405434
Posted Thursday, January 10, 2013 7:33 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:20 AM
Points: 5,231, Visits: 5,106
Its the metadata of objects like views, triggers, procedures.

You can query it, using a open ended like clause on the definition column for the table name in question

SELECT * FROM sys.sql_modules WHERE definition LIKE '%tablename%'

If it brings anything back you know you need to change them objects.
Its not a 100% complete list as you may have processes on other servers, systems, apps which reference the table, so you would need to do a complete invesitgation as to what connects to the DB, and loop through source code or jobs etc to find out what else will break.

Or you could just go gung-ho and change the table and wait to see what breaks.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1405444
Posted Thursday, January 10, 2013 7:38 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 6:42 AM
Points: 416, Visits: 2,547
Great, Thanks again.

SueTons.


Regards,
SQLisAwe5oMe.
Post #1405455
Posted Thursday, January 10, 2013 11:23 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 1:58 PM
Points: 367, Visits: 615
Easiest way to determine what else will need to be changed is to right-click the table in SSMS and click View Dependencies. This will tell you everything that references it with the least effort.
Post #1405576
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse