Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ways to rename/replace tables with minimal disruption

Posted on 2014-02-20
3
Medium Priority
?
235 Views
Last Modified: 2014-03-24
I am looking for suggestions. we have a fairly popular table that will normally carry up to 200000 sessions for most of the day. It has been marked as a '24/7 do not disrupt' critter.
However at the same time we need to rename it and replace it with a different one due to numerous preferred changes. The sessions by the way are persistent. What I am looking for are possible ways to accomplish the change.
(At this time my feeling is to hide it behind server maintenance by placing it in single user in front of the mandatory server restart,with rollback since they are only readers, doing the change and then multiuser>restart and done.
but my thought is perhaps there is a better way. S that is what I am looking for.
Requirements:
must be sql server 2005
the users are all using a vb application. It might be possible to  point to a substitute dbname that points back to the tables replacing the tables (view?)
0
Comment
Question by:qube09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39876542
You don't do a server restart. That is the most disruptive way. If you want you can create a second table form the original one and then simply rename it when the usage is less possible, during the night maybe:

Lets say your table name is my_table. You will create a new one called my_table_new and then:

EXEC sp_rename my_table, my_table_old
GO
EXEC sp_rename my_table_new, my_table
GO

Open in new window

0
 
LVL 19

Assisted Solution

by:regmigrant
regmigrant earned 750 total points
ID: 39876586
I think you need to consider how the code will be updated to point to the new table before you worry about the renaming itself. Your strategy for that will probably reveal the most useful way to handle the table changes. In a previous project we did it using a synonym so the code was abstracted from the underlying table and we could manipulate it with impunity, once the code rollout was complete and the number of hits on the 'old' table reduced to near zero we retired the synonym and left the new table in place

http://technet.microsoft.com/en-US/library/ms191230(v=sql.90).aspx
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 750 total points
ID: 39877114
You shouldn't need to restart the SQL instance.

You should consider allowing existing code to continue to referenced the old name for a while; that helps to insure that existing code doesn't break.

To do that, do these steps back-to-back immediately, as part of the same batch/script:

EXEC sp_rename 'dbo.old_table_name', 'new_table_name'
CREATE SYNONYM dbo.old_table_name FOR dbo.new_table_name

After the synonym is created, SQL code using the old_table_name will still reference the new table name when it executes.


>> It might be possible to  point to a substitute dbname that points back to the tables replacing the tables (view?)  <<

I think the synonym gives you what you're referring to there, if I understand it correctly.


Edit: If the new table structure is not compatible with the old one, you can create a view with the old name instead of using a synonym.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question