Solved

ways to rename/replace tables with minimal disruption

Posted on 2014-02-20
3
229 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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

756 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