Solved

View on several databases sql server 2005

Posted on 2007-03-17
6
148 Views
Last Modified: 2010-03-19
Is there a way to create a view in one database that combines tables from several databases.  What I'm trying to do is this:
Since my database has huge amounts of data, I want to split out by year, since data from previous years is seldom changed, then it isn't in the curent database.
But sometimes users like to report on old data.  What I would like to do is have a view which combines the data and when I report, use this view as opposed to the table which only hold current data.
Does this make sense, or has someone done something similar?
0
Comment
Question by:Fraser_Admin
6 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 18740996
you can use the following syntax:

select * from dbname.dbo.tablename
union
select * from otherdbname.dbo.tablename
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18741110
yes perfectly possible,

you may also like to examine/consider distributed/partitioned views if you can organise a partitioning key/range

just use the 3/4 part name to reference the tables...

servername.databasename.ownername.tableorVieworfunctionName
0
 

Author Comment

by:Fraser_Admin
ID: 18741407
lowfatspread, i'm not sure what you are suggesting?  what are distributed/partitioned views. and what is key/range.  is there a better/more efficient way of doing this than the method emoreau suggested above?  i'm looking for the method that returns the data quickest.  right now i have several hundred thousand records in a table which is from 2003 - Now.  It is sometimes slow running queries, so I would like to try splitting by year.  Maybe there is a better solution for me (ie. indexing??)  I've tried indexing before, but when I show the execution plan, it never seems to use my index.  Perhaps I'm doing something wrong....
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18746737
partitioned views are a way of allowing you to split your data across diferent tables even different databases and servers to imprve overal performance....

the method eventually comes down to defining a view similar to emoreaus... however because you have defined a partitoning key (a range..) which effectively constrain the data to 1 partiton (table) sql server just accesses the
table it requires....


several hundred thousand rows doesn't sound that large...

i'd expect your problems to be better address with index changes....

what are your current indexes ?
what are your queries like?

 
0
 
LVL 1

Expert Comment

by:engayman01
ID: 18746944
Hi,
Just named your database in the query.
databaseName.dbo.TableName.

Best Regards
0
 

Author Comment

by:Fraser_Admin
ID: 18775627
I am having problems putting new indicies.  It times out.  I'm not even sure I completely understand how they work.  I have developed a scaling system.  I track bill number, contract information, product information, payment information, etc.  Mainly on 3 different data tables, and several lookup tables.  So most of my fields are integer values referencing lookup tables.

I only have my primary key on the table right now.

How do you go about deciding what to use as an index.  I would think common queries would be a good idea.  ie. if people generally want to show the weights delivered based on contract, would I make an index based on the contract and weight?

One example report would be delivery date entered by user and a result is sumed weights by contract.

Hopefully you understand my question.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

12 Experts available now in Live!

Get 1:1 Help Now