Link to home
Start Free TrialLog in
Avatar of UnderSeven
UnderSeven

asked on

How to reference multiple db's in T-sql

I use one db for storing data, it is built from a restore of another db.  We'll call this db REPORT.  Another database I put my actual stored procedures and functions on. I'll call this one SPS

Typically this isn't an issue, we simply reference the appropriate db in the FROM clause, but I want to know how I can make it so I can have T-SQl pointed to look in specific places for functions.  For isntance, I don't want to have to type 'SPS.DBO.FUNCTIONNAME()' everytime I want to use one of those functions.  How can I make it so I just have to type the function name?
Avatar of devlab2012
devlab2012
Flag of India image

you can use as three part name as DBName.Schema.Objectname. Objectname is your table or sp etc. You can simply ignore schema

e.g.

select * from MyDB..MyTable
Avatar of UnderSeven
UnderSeven

ASKER

Is there anyway to include it like you would in a c language? So I can avoid writing anything but the function?
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.