Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Change table name
Change table name
Rate Topic
Display Mode
Topic Options
Author
Message
SQLCrazyCertified
SQLCrazyCertified
Posted Thursday, January 10, 2013 6:56 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 312,
Visits: 1,867
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.
Post #1405406
anthony.green
anthony.green
Posted Thursday, January 10, 2013 7:03 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
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
SQLCrazyCertified
SQLCrazyCertified
Posted Thursday, January 10, 2013 7:07 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 312,
Visits: 1,867
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.
Post #1405416
anthony.green
anthony.green
Posted Thursday, January 10, 2013 7:11 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
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
SQLCrazyCertified
SQLCrazyCertified
Posted Thursday, January 10, 2013 7:13 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 312,
Visits: 1,867
Thanks Anthony....appreciate your quick response.
SueTons.
Post #1405424
SQLCrazyCertified
SQLCrazyCertified
Posted Thursday, January 10, 2013 7:26 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 312,
Visits: 1,867
[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.
Post #1405434
anthony.green
anthony.green
Posted Thursday, January 10, 2013 7:33 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
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
SQLCrazyCertified
SQLCrazyCertified
Posted Thursday, January 10, 2013 7:38 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 312,
Visits: 1,867
Great, Thanks again.
SueTons.
Post #1405455
jerry-621596
jerry-621596
Posted Thursday, January 10, 2013 11:23 AM
Old Hand
Group: General Forum Members
Last Login: 2 days ago @ 12:31 PM
Points: 363,
Visits: 578
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.