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
Solved

ways to rename/replace tables with minimal disruption

Posted on 2014-02-20
3
227 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
3 Comments
 
LVL 26

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 250 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 69

Accepted Solution

by:
Scott Pletcher earned 250 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

790 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