Procedures and functions with cross-database dependencies

  • Long story short - our company's primary operational database is poorly designed and has been poorly maintained in the past. We can't rely on the suppliers to improve things for our purposes so we're looking into developing a database containing objects that would act on the former database (e.g. cleanup procedures, additional data storage and reporting functions).

    Would anyone know what the extent of performance costs is of using procedures, functions or views from one database on data from another if both databases are on the same server? Are there any reasons why this might be a horrible idea in general? I want to avoid creating objects in the existing database as it's already cluttered with hundreds of tables and thousands of SPs...

  • on the same server, i believe it's no problem; every query eventually gets resolved to all objects to thee part naming conventions...database.schema.object;

    I have a system I babysit that we recently migrated to use Synonyms for the three part objects, to make it easier to build development vs QA vs production instances.

    you can look at the execution plans of those kinds of multi database operations, there's nothing different than when all the objects are in the same database.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Excellent, that's just what I wanted to hear!

  • I absolutely agree with Lowell but let me give you another hint that will save much in the area of agony in the future....

    Don't use anything more than the 2 part naming convention in any of your code. Use only the 2 part naming convention. If a table is in a different database, then create a synonym that's naming using 2 part naming to point to the object in the other database.

    Why? First, it hurts nothing for performance. Second, it makes programming easier. Third, you won't have to change any of your code if you decide to move a table to different database or even rename the whole database. Instead you only need to change the synonym(s).

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply