sql - How to reference another Database in a generic manner -
we have live , demo systems, each using of pair of databases. 1 database reports other.
quite demo site has reference this
select columns otherdatabase_demo.dbo.tablename
so live version say:
...from otherdatabase.dbo.tablename
when comes publsihing compare stored procedures between live , demo (using dbforge schema compare in case) every differing reference highlighted, , creates lot of noise.
is there way abstract these references can make distinction in 1 single location?
yes, use synonym. in 1 database:
create synonym dbo.mytablename otherdatabase_demo.dbo.tablename;
and in live version:
create synonym dbo.mytablename otherdatabase.dbo.tablename;
now script can say...
select columns dbo.mytablename
...in both databases, allowing procedures identical.
your diff scripts may pick different definitions synonyms, can ignore (either tool or consciously).
we've asked ability alias database, don't understand how useful be:
http://connect.microsoft.com/sqlserver/feedback/details/288421/allow-create-synonym-for-database
Comments
Post a Comment