SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Change table name


Change table name

Author
Message
SQLisAwE5OmE
SQLisAwE5OmE
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3170 Visits: 3075
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.
anthony.green
anthony.green
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25320 Visits: 6519
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
When a question, really isn't a question - Jeff Smith
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


SQLisAwE5OmE
SQLisAwE5OmE
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3170 Visits: 3075
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.
anthony.green
anthony.green
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25320 Visits: 6519
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
When a question, really isn't a question - Jeff Smith
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


SQLisAwE5OmE
SQLisAwE5OmE
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3170 Visits: 3075
Thanks Anthony....appreciate your quick response.

SueTons.

Regards,
SQLisAwe5oMe.
SQLisAwE5OmE
SQLisAwE5OmE
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3170 Visits: 3075
[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.
anthony.green
anthony.green
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25320 Visits: 6519
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
When a question, really isn't a question - Jeff Smith
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


SQLisAwE5OmE
SQLisAwE5OmE
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3170 Visits: 3075
Great, Thanks again.

SueTons.

Regards,
SQLisAwe5oMe.
jerry-621596
jerry-621596
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1383 Visits: 649
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search