Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Synonyms

 
   Database Help (Home) -> Programming RSS
Next:  RDLC 2008 Error in print layout mode  
Author Message
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 1) Posted: Fri Jun 18, 2010 6:44 am
Post subject: Synonyms
Archived from groups: microsoft>public>sqlserver>programming (more info?)

We have a number of stored procs/functions in a support databse which
looks to a production database for the data. Rather than do this in
each procedure:

SELECT col1 FROM ProdServer.dbo.MyTable

We were hoping to create a synonym, say SourceDB, for ProdServer.dbo
and prepend it to the table name like this:

SELECT col1 FROM SourceDB.MyTable

Then we can easily change the data source simply by changing the
synonym.

Unfortunately this doesn't work. I've only been able to create a
synonym that points to a specific databse object but that means I need
to create and maintain one synonym for each object. Is there any way
to do what I'm asking?

Thanks

Carl

 >> Stay informed about: Synonyms 
Back to top
Login to vote
Eric Isaacs

External


Since: May 13, 2008
Posts: 367



(Msg. 2) Posted: Fri Jun 18, 2010 10:26 am
Post subject: Re: Synonyms [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Synonyms point to specific database objects. They do not apply to the
server in general. But your idea of changing the synonym is sound and
is a way to make your code dynamic without doing dynamic SQL.

The table and column information is stored in the
Inforation_schema.tables and information_schema.columns views. You
could create synonyms to say each information_schema.columns view in
each of your databases, then select * from the columns views in each
database to determine which tables have col1 and create a synonym on
the fly that points to that table in that database and execute the
other procedure that utilizes the synonym.

-Eric Isaacs

 >> Stay informed about: Synonyms 
Back to top
Login to vote
John Bell

External


Since: Jan 11, 2008
Posts: 157



(Msg. 3) Posted: Fri Jun 18, 2010 4:25 pm
Post subject: Re: Synonyms [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 18 Jun 2010 06:44:17 -0700 (PDT), SetonSoftware
wrote:

>We have a number of stored procs/functions in a support databse which
>looks to a production database for the data. Rather than do this in
>each procedure:
>
>SELECT col1 FROM ProdServer.dbo.MyTable
>
>We were hoping to create a synonym, say SourceDB, for ProdServer.dbo
>and prepend it to the table name like this:
>
>SELECT col1 FROM SourceDB.MyTable
>
>Then we can easily change the data source simply by changing the
>synonym.
>
>Unfortunately this doesn't work. I've only been able to create a
>synonym that points to a specific databse object but that means I need
>to create and maintain one synonym for each object. Is there any way
>to do what I'm asking?
>
>Thanks
>
>Carl

How about using views?

John
 >> Stay informed about: Synonyms 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 4) Posted: Fri Jun 18, 2010 6:25 pm
Post subject: Re: Synonyms [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

SetonSoftware (seton.software@verizon.net) writes:
> We have a number of stored procs/functions in a support databse which
> looks to a production database for the data. Rather than do this in
> each procedure:
>
> SELECT col1 FROM ProdServer.dbo.MyTable
>
> We were hoping to create a synonym, say SourceDB, for ProdServer.dbo
> and prepend it to the table name like this:
>
> SELECT col1 FROM SourceDB.MyTable
>
> Then we can easily change the data source simply by changing the
> synonym.
>
> Unfortunately this doesn't work. I've only been able to create a
> synonym that points to a specific databse object but that means I need
> to create and maintain one synonym for each object. Is there any way
> to do what I'm asking?

No, but you can vote for this feature here:
https://connect.microsoft.com/SQLServer/feedback/details/311079/expand-
synonym-to-other-entities-database-linked-server

In the meanwhile, you could write a stored procedure that loops over
of the synonyms, and retargets them to a different database.

--
Erland Sommarskog, SQL Server MVP, esquel DeleteThis @sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: Synonyms 
Back to top
Login to vote
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 5) Posted: Mon Jun 21, 2010 8:55 am
Post subject: Re: Synonyms [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jun 18, 5:38 pm, Erland Sommarskog wrote:
> SetonSoftware (seton.softw...@verizon.net) writes:
> > We have a number of stored procs/functions in a support databse which
> > looks to a production database for the data. Rather than do this in
> > each procedure:
>
> > SELECT col1 FROM ProdServer.dbo.MyTable
>
> > We were hoping to create a synonym, say SourceDB, for ProdServer.dbo
> > and prepend it to the table name like this:
>
> > SELECT col1 FROM SourceDB.MyTable
>
> > Then we can easily change the data source simply by changing the
> > synonym.
>
> > Unfortunately this doesn't work. I've only been able to create a
> > synonym that points to a specific databse object but that means I need
> > to create and maintain one synonym for each object. Is there any way
> > to do what I'm asking?
>
> No, but you can vote for this feature here:https://connect.microsoft.com/SQLServer/feedback/details/311079/expand-
> synonym-to-other-entities-database-linked-server
>
> In the meanwhile, you could write a stored procedure that loops over
> of the synonyms, and retargets them to a different database.
>
> --
> Erland Sommarskog, SQL Server MVP, esq....RemoveThis@sommarskog.se
>
> Links for SQL Server Books Online:
> SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
> SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
> SQL 2000:http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -
>
> - Show quoted text -

Very good enhancement idea! I just voted for it. Thanks for pointing
it out.

Carl
 >> Stay informed about: Synonyms 
Back to top
Login to vote
SetonSoftware

External


Since: Dec 03, 2008
Posts: 17



(Msg. 6) Posted: Mon Jun 21, 2010 8:56 am
Post subject: Re: Synonyms [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jun 18, 3:55 pm, John Bell wrote:
> On Fri, 18 Jun 2010 06:44:17 -0700 (PDT), SetonSoftware
>
>
>
>
>
> wrote:
> >We have a number of stored procs/functions in a support databse which
> >looks to a production database for the data. Rather than do this in
> >each procedure:
>
> >SELECT col1 FROM ProdServer.dbo.MyTable
>
> >We were hoping to create a synonym, say SourceDB, for ProdServer.dbo
> >and prepend it to the table name like this:
>
> >SELECT col1 FROM SourceDB.MyTable
>
> >Then we can easily change the data source simply by changing the
> >synonym.
>
> >Unfortunately this doesn't work. I've only been able to create a
> >synonym that points to a specific databse object but that means I need
> >to create and maintain one synonym for each object. Is there any way
> >to do what I'm asking?
>
> >Thanks
>
> >Carl
>
> How about using views?
>
> John- Hide quoted text -
>
> - Show quoted text -

Unfortunately, views won't work here. They would result in the same
limitation as synonyms.

Carl
 >> Stay informed about: Synonyms 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
sys.synonyms: how to determine target database & object na.. - I have synonyms in the database: CREATE SYNONYM MySynonym FOR MyDatabase.dbo.MyTable There is also the view sys.synonyms with a structure like sys.objects. How can I determine the target database and table name? Are there any other views (like..

need help with query - I want to sum the records in a table (u) which have 'P.M.' in a field value and test against a fixed limit something to the effect of : case when SUM(substring(u.sTime,1,4)='P.M.') <= 64 Then .... except it should work ...

Next?? - I have a field stored as NTEXT(16). I need to replace some of the content in this field. I know the replace function doesnt work. I see there is UPDATETEXT - is this the ONLY way to do it ?? 'cos it looks quite complicated? thanks, Justin

How can I get the resultset from a stored procedure - I have a stored procedure which will output a table. How can I use a sql statement to get the result of the sp? Thanks a lot

Audit V2 - I am looking to write a SQL script that will show me for each table, in all the databases on a server, which users / groups have access. In addition, I want to break the access into whether it is SELECT, UPDATE, INSERT or DELETE permissions. Is this..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]