Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Designing Cross Database Queries Expand / Collapse
Author
Message
Posted Tuesday, February 22, 2005 1:12 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 4:31 PM
Points: 32,780, Visits: 14,941
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/sjones/designingcrossdatabasequeries.asp






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #163314
Posted Wednesday, March 09, 2005 1:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, February 28, 2009 12:21 PM
Points: 32, Visits: 13

Your Idea looks pretty good, if we are dealing small amount of data.

in case, if the data grows larger, the performace going to get a hit.

why i am saying this is, we can't index the views, like you siad in your examples. since it requires schema binding. so Querying or any DML statments on the view that is created from other database tables will be much slower.

i hope that i make sence

 

ramesh




Post #166472
Posted Wednesday, March 09, 2005 7:15 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, January 20, 2009 12:12 PM
Points: 285, Visits: 94

Steve,

Good solution. I agree partially with Ramesh comments, If data grows there will be performence hit but we could create index on view.

How about putting same logic in user defined function passing parameters to filter out the data?.

 




Post #166573
Posted Wednesday, March 09, 2005 7:31 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 31, 2013 6:00 AM
Points: 1,090, Visits: 58

Ramesh,

I disagree. When the databases are on the same server, query plans are built the same from a view in the view-database as if it were querying on the base-table-database. You still have the ability to index the base tables to optimize the views. You only lose the functionality when you use linked servers in the views.

We have an environment for reporting here that needs to use dynamic aggregations on products. The product aggregations are on what we call market definitions and product groups (1-m-m; market def-prod grp-prod). Users have the ability to add and remove products from these groupings based on rules regarding attributes of the products. In our environment, we have a reference database with the most recent product data available that have views in the market definition database referencing them. This allows us to load a separate (parallel) database for the product reference while still using the prior load's data for updates to the market definitions. Once the new product data is loaded, we switch database names - making the newly loaded data the live reference data. Views work great with this implementation.

On the reporting end, we have several data marts that have views in them referencing the OLTP (Market Definition) database (we actually do the same for data mart loads - load to a separate database and switch database names). This is the only time I've ever considered mixing OLTP and Reporting applications' databases on the same server.

My point is that during tuning exercises, we've been very successful in tuning the base tables to improve view performance.




Post #166579
Posted Wednesday, March 09, 2005 8:11 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, August 24, 2009 2:13 PM
Points: 83, Visits: 16

For clarification you can index views but only the Enterprise, Developer, and Evaluation versons of SS2K support them. You can how ever create them in all versions of SS2K for migration from one edition to another,  but the query optimiser will not use the index in Standard and Personal versions of SS2K.

I don't know if SS2005 changed this though.




Imagination is more important than knowledge.

– Albert Einstein
Post #166589
Posted Wednesday, March 09, 2005 8:12 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, March 10, 2014 1:21 PM
Points: 885, Visits: 1,526

My company produces accounting software for a specific industry.  Often our clients have multiple database's because the government or some other legal entity has one or more regulations requiring this seperation.  For these clients it is impossible to perform consolidated reporting using standard reports provided since they have data in multiple databases.  The idea of using a view to pull data from other databases is in my opinion a great idea.  Using aview minimizes the amount of work needed and the amount of space required to do this.  Copyinig data from many databases to a single DB takes time & resources such as space.  Why do something like this when views that pull in data from other DB's can be used to do the same thing?

 

Ed



Kindest Regards,

A Democracy works great until the day you find yourself on the sheep side of a vote between 5 wolves and 4 sheep on what’s for dinner when neither have eaten in many days. A free Republic where the rights of the few and the individual are protected is the only one in which Freedom and Prosperity for all have a chance to blossom.
Post #166590
Posted Wednesday, March 09, 2005 8:33 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 3:42 AM
Points: 275, Visits: 737

I like the view idea better than explicitly referencing objects in other DBs. 

But to me the idea of having to grant my users rights to the underlying tables in the other DBs is significantly worse/more painful than simply enabling cross-database ownership chaining. 

On my production servers the only db-owner we allow is sa, and cross-db ownership chaining is enabled.  We use similar approach for cross-db views, and users have no rights to underlying tables.  Is there some security downside to this approach that I'm missing?




Post #166595
Posted Wednesday, March 09, 2005 8:37 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 8:03 PM
Points: 6,266, Visits: 2,027

>>>For clarification you can index views but only the Enterprise, Developer, and Evaluation versons of SS2K support them.<<<

Allow me to differ

Indexed views are suported in the standard edition also and the only thing you have to keep in mind is that you must use the NO EXPAND option when refering to the indexed views!

 




* Noel
Post #166596
Posted Wednesday, March 09, 2005 8:41 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 8:03 PM
Points: 6,266, Visits: 2,027

Ramesh,

The views on sql server are EXPANDED by default when creating the execution plan therefore using the correct indexes on the base tables (like bbdpres  suggested) will give you the performance benefits required when tunning.

The only case that views afect performance is when the nested level is extremely high and you are performing some unneeded joins or calculations

HTH

 




* Noel
Post #166597
Posted Wednesday, March 09, 2005 10:02 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, February 20, 2009 10:16 AM
Points: 525, Visits: 26

I prefer to use a linked server.  This method is the most flexible and supports multiple environments (dev,test,prod).

You imply in your article that the linked server name must be the actual server name.  This is not true.  Instead of using the "SQL Server" option in the linked server creation dialog, if you use the "Other data sources" option and point to the OLE DB driver for SQL Server, you can now set the linked server up with any name you want.  Now, you can have a linked server named PubsLink in every environent and code does not have to change, only the details of the linked server.  Also, when that subscription database grows in size or users to the point where you HAVE to move it off to it's own server, there are no code changes to make, only details of the linked server and it just works.




Post #166625
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse