Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 14th, 2007, 01:12 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default Aliasing a database

OK, sorry for all the posts. I am trying to find the best way to accomplish a specific task and I keep hitting some walls.

I got the linked server thing to work, and this question is somewhat related to that. Is there any way to "alias" a database? Let me explain...

Our application has two databases. The main "production" database and an archive database. We have a process in which database is "archived" from the production db to the archive db. However, we can't always guarantee that the archive db will always be called the same thing.

So, we want to be able to Alias it so that the code in the production db never needs to be changed.

Does this make sense?

Any input is greatly appreciated...

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
__________________
========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
Reply With Quote
  #2 (permalink)  
Old February 14th, 2007, 01:47 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

So, the answer is a combination of both Linked Servers and Synonyms. Synonyms allow you to "alias" database objects, even objects in other databases, AND databases on other servers.

To alias a db object in a database on the same machine, the syntax is real easy:

CREATE SYNONYM aliasname FOR database.dbo.objectname
GO
SELECT * FROM aliasname

If you want to alias an object on another server, you first need to create a LINKED SERVER then create the synonym using the Linked Server name.

CREATE SYNONYM aliasname FOR linkedservername.database.dbo.objectname
GO
SELECT * FROM aliasname

Pretty cool...


Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
Reply With Quote
  #3 (permalink)  
Old February 18th, 2007, 01:05 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Sorry for the late reply...

SYNONYM will certainly work for SQL Server 2005... if you only have SQL Server 2000, a view works very well and has some other advantages, as well. For example, as dumb as it sounds, some of our folks need the ability to work with current information AND the archived information at the same time. Rather than them doing a JOIN in all their code, we simply made a view that does the join. For example, we have a current table called InvoiceDetail and an archived table (for things more than 120 days old) also called InvoiceDetail but in a different database. We called the view "InvoiceDetailALL".

This method will allow you to split voluminous data into online, near-line, and "almost off-line" databases and make changes in the background without having to change a lick of foreground code... Can't necessarily do that even with a synonym... unless of course, the synonym refers to a view :D

--Jeff Moden
Reply With Quote
  #4 (permalink)  
Old February 18th, 2007, 04:47 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thanks for the reply Jeff. Luckily we're using SQL Server 2005. However, you're solution may also come in handy if we aren't achieving the results we expect via SYNONYMS.

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to restore database in C#2005 database acmuralee MySQL 0 March 25th, 2008 04:42 AM
Access database database format itHighway Access 0 February 24th, 2008 06:34 PM
Microsoft JET Database Database Engine (0x80040E09 cannielynn0312 Classic ASP Professional 2 December 17th, 2007 02:50 AM
Copying Table From one Database To Anoter Database jayanth_nadig VB Databases Basics 1 June 19th, 2006 02:39 PM



All times are GMT -4. The time now is 05:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.