Solved

ways to rename/replace tables with minimal disruption

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Join 4 35
SQL Field Length for Email Address 3 18
Getting same value for every field in SQL 2 34
Sql Query 4 21
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now