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 «««1234

Using Views Expand / Collapse
Author
Message
Posted Thursday, August 14, 2014 2:01 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, November 21, 2014 8:18 AM
Points: 1,533, Visits: 2,259
Steve Jones - SSC Editor (8/13/2014)
Jason Shadonix (8/3/2014)


We use synonyms here and there, and have never had any issues with them "not working".

We use SPs over SQL code in our application whenever possible. In some organizations it might shift a lot of load to the DBAs or make the developers have to wait on DBAs to get them changed if needed, but it also allows changes to be made "on the fly" a lot easier in many cases without the need to do a code release. It just depends on the organization/environment you're working in.


Want to write about how you use synonyms? Always looking for descriptions of real world implementations.


Hmm...I could probably come up with something in the next week or two.


The Redneck DBA
Post #1603473
Posted Friday, September 5, 2014 7:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 5, 2014 7:34 AM
Points: 10, Visits: 102
Synonyms can be used to simplify code when doing cross-database work. They are especially helpful for standardizing code when the external database name varies from environment to environment. Consider these databases:
* MyDB_dev
* MyDB_prod
* YourDB_dev
* YourDB_prod

Besides the environment-specific databases, this would work where there is a set of databases (MyDB and YourDB) for each project or client.

MyApplication connects to either MyDB_dev or MyDB_prod. Code in MyDB (or MyApplication) needs to use YourObject in YourDB. Rather than using messy/repetitive/dynamic code to access either YourDB_dev.YourObject or YourDB_dev.YourObject , we encapsulate the database name differences in synonyms.

On MyDB_dev: CREATE SYNONYM dbo.YourObject FOR YourDB_dev.dbo.YourObject;
On MyDB_prod: CREATE SYNONYM dbo.YourObject FOR YourDB_prod.dbo.YourObject;

Once the synonyms are set up (correctly), all code is instance-agnostic, and there is no risk of getting dev data in prod.
Post #1610893
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse