Showing posts with label qualified. Show all posts
Showing posts with label qualified. Show all posts

Sunday, February 26, 2012

Fully Qualified Query Accross Databases

Are there any perfmonace or query optimization limitations or issues that arise when issueing a fully qualified query across multiple databases on the same Instance of SQL Server. In other words are all features of query optimization fully supported in queries that span databases on the same Instance.

The only limitations that I'm aware of are the same limitations if the queries only run against one database, i.e. the databases have to be properly optimized for performance. If one database is properly indexed and one is not the bottleneck will be the database that isn't properly indexed.
|||

That is a fact, but I am really trying to determine if there are any optimizer limitations or nuances like there are if you are using partitioning.

|||The fact that there may be partitioning really isn't relevant since partitioning is only undertaken to optimize query performance anyway by distributing data across multiple files. As I mentioned, if the databases are optimized, whether through the use of partitioning or any other strategy, then cross database queries aren't an issue. There aren't any optimizer limitations or nuances that need to be considered.

If you were performing distributed queries across multiple linked servers or across multiple resource engines, i.e. SQL Server/Oracle then there might be some things to consider but even then, the issue would probably still come down to whether the databases are properly optimized.

Fully qualified object names help reuse of execution plans.

Fully qualified object names help reuse of execution plans.
Is this true? Discuss.
Also, what constitutes fully qualified?
Is it
server.database.owner.object
or can you get away with
database.owner.object
and still resuse your execution plans?
ThanksYou should read this KB. Even though it is for 2005 most of the same
principles still apply.
http://www.microsoft.com/technet/pr...005/recomp.mspx
As for your question of what does fully mean well that depends. Mostly it
means you should always specify the object owner along with the object.
dbo.yoursp or dbo.yourtable etc.
If you are accessing an object from within the same db then just specify the
owner and the object. Do not specify the database as it is no necessary and
actually invokes a few more lines of code than necessary. If you need to
specify an object in another db on the same server than you must specify
that as well.
OtherDB.dbo.Object
Andrew J. Kelly SQL MVP
"Damien" <Damien@.discussions.microsoft.com> wrote in message
news:2BBC6EA6-2E85-4643-8E07-16E031D8E8A9@.microsoft.com...
> Fully qualified object names help reuse of execution plans.
> Is this true? Discuss.
> Also, what constitutes fully qualified?
> Is it
> server.database.owner.object
> or can you get away with
> database.owner.object
> and still resuse your execution plans?
> Thanks
>|||Hi
http://msdn.microsoft.com/library/d...br />
4azp.asp
If you want more information, get yourself "Inside SQL Server 2000" by Kalen
Delaney.
owner.object is good enough for re-use.
--
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Damien" <Damien@.discussions.microsoft.com> wrote in message
news:2BBC6EA6-2E85-4643-8E07-16E031D8E8A9@.microsoft.com...
> Fully qualified object names help reuse of execution plans.
> Is this true? Discuss.
> Also, what constitutes fully qualified?
> Is it
> server.database..object
> or can you get away with
> database.owner.object
> and still resuse your execution plans?
> Thanks
>

Fully Qualified names?

Hi all
A collegeue recently found an item on
http://www.sql-server-performance.c..._procedures.asp (do a search on
the page to "fully qualified name")
In theory this does make sense, and I can understand what the item is
getting at. I work with a team of 20 developers, and we had not implemented
that item.
I decided that before telling everyone to change the thousands of stored
procedures to use this convention, I wanted to be sure that it was worth it.
Anyway, I did a test using SSMS and it didn't seem to matter if I used just
the procedure name, a two part name or a three part name.
The article was written a while ago, so it must be directed at SQL2000. I'd
like to perform a better test to prove this item one way or another.
Can anyone suggest a fair, method of testing this claim and being able to
properly and fairly mesure the difference?
Regards
Colin Dawson
www.cjdawson.comHi, Colin

> Anyway, I did a test using SSMS and it didn't seem to matter if I used
> just the procedure name, a two part name or a three part name.
Well, I think if you specify fully qualified name it will help to SQL
Server to "find" the object more quickly , I mean not to run thro all
objects that have DBO. or all default schema , so it is just my point
of view
"Colin Dawson" <newsgroups@.cjdawson.com> wrote in message
news:Udh8g.67139$wl.47904@.text.news.blueyonder.co.uk...
> Hi all
> A collegeue recently found an item on
> http://www.sql-server-performance.c..._procedures.asp (do a search
> on the page to "fully qualified name")
> In theory this does make sense, and I can understand what the item is
> getting at. I work with a team of 20 developers, and we had not
> implemented that item.
> I decided that before telling everyone to change the thousands of stored
> procedures to use this convention, I wanted to be sure that it was worth
> it. Anyway, I did a test using SSMS and it didn't seem to matter if I used
> just the procedure name, a two part name or a three part name.
> The article was written a while ago, so it must be directed at SQL2000.
> I'd like to perform a better test to prove this item one way or another.
> Can anyone suggest a fair, method of testing this claim and being able to
> properly and fairly mesure the difference?
> Regards
> Colin Dawson
> www.cjdawson.com
>|||On Wed, 10 May 2006 08:10:28 GMT, Colin Dawson wrote:

>Hi all
>A collegeue recently found an item on
>http://www.sql-server-performance.c..._procedures.asp (do a search o
n
>the page to "fully qualified name")
>In theory this does make sense, and I can understand what the item is
>getting at. I work with a team of 20 developers, and we had not implemente
d
>that item.
>I decided that before telling everyone to change the thousands of stored
>procedures to use this convention, I wanted to be sure that it was worth it
.
>Anyway, I did a test using SSMS and it didn't seem to matter if I used just
>the procedure name, a two part name or a three part name.
>The article was written a while ago, so it must be directed at SQL2000. I'
d
>like to perform a better test to prove this item one way or another.
>Can anyone suggest a fair, method of testing this claim and being able to
>properly and fairly mesure the difference?
Hi Colin,
Contrary to what this article says, there's no need to database-qualify
any objects (unless they are in a different database of course).
Owner qualifying is important, though, for the following two reasons:
1. Reduce chance of unexpected bugs. (Example: EXEC MyProc suddenly
throws errors when executed by Alice, becuase she created a procedure
Allice.MyProc yesterday)
2. Performance gain. (EXEC MyProc for Alice takes two lookups: first for
Alice.MyProc, then [if the former doesn't exist] for dbo.MyProc).
The performance gain is real, but in most cases not big enough to
warrant the cost of changing thousands of existing stored procedures.
Just make it your policy to demand that all table, view, and procedure
names shoould be owner-qualified in new code, and that the owner should
be added when changing any existing code (exempting bugfixes and small
changes under heavy time pressurre).
Hugo Kornelis, SQL Server MVP|||Colin Dawson (newsgroups@.cjdawson.com) writes:
> A collegeue recently found an item on
> http://www.sql-server-performance.c..._procedures.asp (do a
> search on the page to "fully qualified name") In theory this does make
> sense, and I can understand what the item is getting at. I work with a
> team of 20 developers, and we had not implemented that item.
> I decided that before telling everyone to change the thousands of stored
> procedures to use this convention, I wanted to be sure that it was worth
> it. Anyway, I did a test using SSMS and it didn't seem to matter if I
> used just the procedure name, a two part name or a three part name.
Including the database name is meaningless, and only increases the
complexity of the programming. (Since you need to get to get the database
from somewhere, and hard-coding it seems like a bad idea.)
Including schema/owner on the other hand matters.
Let's first look at this on SQL 2000. On SQL 2000, each user has a default
schema with the same name as the user name. Thus, if fred says
EXEC some_sp
(or make this call through RPC), SQL Server will first lookup "some_sp" in
the cache, including the uid. If there is a fred.some_sp, there will be a
cache hit, else a cache miss. Later SQL Server will look up some_sp in
metadata, and when fred.some_sp is missing, it will try dbo.some_sp, which
it will find in the cache.
On the other hand, if fred says:
EXEC dbo.some_sp
he will get a cache hit directly.
On SQL 2005, this is somewhat different, as a user can have dbo as the
default schema. In this case, at least in theory, it should not matter
whether you specify dho or not.
Now, how to set the default schema of a user? Well, if you use the new
command, CREATE USER, the user's default schema will be dbo, and there will
be no schema with the user's name. But if you create users with sp_adduser
out of habit, you will get a schema with the user's name, and that will
be the default schema.
Since you cannot be sure that future users get not added in a proper way,
it appears to be a good recommendation to include schema on SQL 2005 as
well.
As for the question of what the impact is of not including dbo, well I don't
have any numbers, but on a busy system with few cycles to spare, I believe
all those cache misses can cause quite some aggrevation.
I should add that including owner/schema is even more important when you
work with dynamic SQL, be that sp_executesql or parameterised command from
the client (which is sp_executesql anyway). If there is a single unqualified
table in the query, the plan will be private to the user, and cannot be
used by other users. (Again, not if the user's default schema is dbo, but
do not rely on that.)
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks for the info. It's helping me to understand this particular nuance.
In this case, I think that I'm not going to insist on the change. The
reason of this is that the db is accessed from a middle tier. The middle
tier uses connection pooling so we need to standardise on a specific user.
This user we need to setup, to it is safe (in this instance) to rely on the
the schema being set to dbo.
I'll certainly remember this for when I'm working on and dynamic sql (of
which there is currently none in the entire app!)
If we find that the app comes even close to maxing out the processor (very
unlikley at this stage) then I'll take a look at forcing dbo. infront of all
objects.
Thanks for the enlightenment.
Regards
Colin Dawson
www.cjdawson.com
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns97BF808BB6063Yazorman@.127.0.0.1...
> Colin Dawson (newsgroups@.cjdawson.com) writes:
> Including the database name is meaningless, and only increases the
> complexity of the programming. (Since you need to get to get the database
> from somewhere, and hard-coding it seems like a bad idea.)
> Including schema/owner on the other hand matters.
> Let's first look at this on SQL 2000. On SQL 2000, each user has a default
> schema with the same name as the user name. Thus, if fred says
> EXEC some_sp
> (or make this call through RPC), SQL Server will first lookup "some_sp" in
> the cache, including the uid. If there is a fred.some_sp, there will be a
> cache hit, else a cache miss. Later SQL Server will look up some_sp in
> metadata, and when fred.some_sp is missing, it will try dbo.some_sp, which
> it will find in the cache.
> On the other hand, if fred says:
> EXEC dbo.some_sp
> he will get a cache hit directly.
> On SQL 2005, this is somewhat different, as a user can have dbo as the
> default schema. In this case, at least in theory, it should not matter
> whether you specify dho or not.
> Now, how to set the default schema of a user? Well, if you use the new
> command, CREATE USER, the user's default schema will be dbo, and there
> will
> be no schema with the user's name. But if you create users with sp_adduser
> out of habit, you will get a schema with the user's name, and that will
> be the default schema.
> Since you cannot be sure that future users get not added in a proper way,
> it appears to be a good recommendation to include schema on SQL 2005 as
> well.
> As for the question of what the impact is of not including dbo, well I
> don't
> have any numbers, but on a busy system with few cycles to spare, I believe
> all those cache misses can cause quite some aggrevation.
> I should add that including owner/schema is even more important when you
> work with dynamic SQL, be that sp_executesql or parameterised command from
> the client (which is sp_executesql anyway). If there is a single
> unqualified
> table in the query, the plan will be private to the user, and cannot be
> used by other users. (Again, not if the user's default schema is dbo, but
> do not rely on that.)
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx|||Colin Dawson (newsgroups@.cjdawson.com) writes:
> In this case, I think that I'm not going to insist on the change. The
> reason of this is that the db is accessed from a middle tier. The middle
> tier uses connection pooling so we need to standardise on a specific
> user. This user we need to setup, to it is safe (in this instance) to
> rely on the the schema being set to dbo.
And you are on SQL 2005?
Else you need to make that standardised user dbo.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns97C04703D6F1Yazorman@.127.0.0.1...
> Colin Dawson (newsgroups@.cjdawson.com) writes:
> And you are on SQL 2005?
> Else you need to make that standardised user dbo.
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx
Yes, I've been on SQL2005 for the last 12 months of so.
Regards
Colin Dawson
www.cjdawson.com

fully qualified names with named instances

hallo it's unclear to me how to address a named instance using a fully
qualified name (server-name.database-name.owner-name.object-name)
In this syntax, where does the instance name fit?
thanks in advance
Raffaele,
server-name is actually linkedserver-name, which may not actually be the
name of a physical serve. Here is some code from SQL 2005 Books Online
EXEC sp_addlinkedserver
@.server='S1_instance1',
@.srvproduct='',
@.provider='SQLNCLI',
@.datasrc='S1\instance1'
You can see that the instance name is defined in the data source as the
server 'S1' and the instance '\instance1'. The server name of
'S1_instance1' reflects that name, but it could be named
'MyFavoriteLinkedServer' or anything else.
So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance
|||[Server\Instance].database.owner_or_schema.object
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance
|||hallo aaron, this was i tried as first but i got this error
"unable to find 'servername\instancename' in sysservers
"Aaron Bertrand [SQL Server MVP]" wrote:

> [Server\Instance].database.owner_or_schema.object
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
>
>
|||i already tried linking the instance, getting error 15028 - the server
already exists.
In the test case, both the default and the named instance are on the same
server, which is running MSSQL 2000
"Russell Fields" wrote:

> Raffaele,
> server-name is actually linkedserver-name, which may not actually be the
> name of a physical serve. Here is some code from SQL 2005 Books Online
> EXEC sp_addlinkedserver
> @.server='S1_instance1',
> @.srvproduct='',
> @.provider='SQLNCLI',
> @.datasrc='S1\instance1'
> You can see that the instance name is defined in the data source as the
> server 'S1' and the instance '\instance1'. The server name of
> 'S1_instance1' reflects that name, but it could be named
> 'MyFavoriteLinkedServer' or anything else.
> So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
> RLF
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
>
>
|||ok linked server solved! the named instance was already present as "remote
server" since was used for a test replica.
Thanks
"Raffaele" wrote:

> i already tried linking the instance, getting error 15028 - the server
> already exists.
|||OK, thanks for the update. - RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:DA137E75-C8F2-41B3-8B2F-C94344FB3FB4@.microsoft.com...
> ok linked server solved! the named instance was already present as "remote
> server" since was used for a test replica.
> Thanks
> "Raffaele" wrote:
>

fully qualified names with named instances

hallo it's unclear to me how to address a named instance using a fully
qualified name (server-name.database-name.owner-name.object-name)
In this syntax, where does the instance name fit?
thanks in advanceRaffaele,
server-name is actually linkedserver-name, which may not actually be the
name of a physical serve. Here is some code from SQL 2005 Books Online
EXEC sp_addlinkedserver
@.server='S1_instance1',
@.srvproduct='',
@.provider='SQLNCLI',
@.datasrc='S1\instance1'
You can see that the instance name is defined in the data source as the
server 'S1' and the instance '\instance1'. The server name of
'S1_instance1' reflects that name, but it could be named
'MyFavoriteLinkedServer' or anything else.
So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance|||[Server\Instance].database.owner_or_schema.object
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance|||hallo aaron, this was i tried as first but i got this error
"unable to find 'servername\instancename' in sysservers
"Aaron Bertrand [SQL Server MVP]" wrote:

> [Server\Instance].database.owner_or_schema.object
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
>
>|||i already tried linking the instance, getting error 15028 - the server
already exists.
In the test case, both the default and the named instance are on the same
server, which is running MSSQL 2000
"Russell Fields" wrote:

> Raffaele,
> server-name is actually linkedserver-name, which may not actually be the
> name of a physical serve. Here is some code from SQL 2005 Books Online
> EXEC sp_addlinkedserver
> @.server='S1_instance1',
> @.srvproduct='',
> @.provider='SQLNCLI',
> @.datasrc='S1\instance1'
> You can see that the instance name is defined in the data source as the
> server 'S1' and the instance '\instance1'. The server name of
> 'S1_instance1' reflects that name, but it could be named
> 'MyFavoriteLinkedServer' or anything else.
> So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
> RLF
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
>
>|||ok linked server solved! the named instance was already present as "remote
server" since was used for a test replica.
Thanks
"Raffaele" wrote:

> i already tried linking the instance, getting error 15028 - the server
> already exists.|||OK, thanks for the update. - RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:DA137E75-C8F2-41B3-8B2F-C94344FB3FB4@.microsoft.com...
> ok linked server solved! the named instance was already present as "remote
> server" since was used for a test replica.
> Thanks
> "Raffaele" wrote:
>
>

fully qualified names with named instances

hallo it's unclear to me how to address a named instance using a fully
qualified name (server-name.database-name.owner-name.object-name)
In this syntax, where does the instance name fit?
thanks in advanceRaffaele,
server-name is actually linkedserver-name, which may not actually be the
name of a physical serve. Here is some code from SQL 2005 Books Online
EXEC sp_addlinkedserver
@.server='S1_instance1',
@.srvproduct='',
@.provider='SQLNCLI',
@.datasrc='S1\instance1'
You can see that the instance name is defined in the data source as the
server 'S1' and the instance '\instance1'. The server name of
'S1_instance1' reflects that name, but it could be named
'MyFavoriteLinkedServer' or anything else.
So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance|||[Server\Instance].database.owner_or_schema.object
--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> hallo it's unclear to me how to address a named instance using a fully
> qualified name (server-name.database-name.owner-name.object-name)
> In this syntax, where does the instance name fit?
> thanks in advance|||hallo aaron, this was i tried as first but i got this error
"unable to find 'servername\instancename' in sysservers
"Aaron Bertrand [SQL Server MVP]" wrote:
> [Server\Instance].database.owner_or_schema.object
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> > hallo it's unclear to me how to address a named instance using a fully
> > qualified name (server-name.database-name.owner-name.object-name)
> > In this syntax, where does the instance name fit?
> >
> > thanks in advance
>
>|||i already tried linking the instance, getting error 15028 - the server
already exists.
In the test case, both the default and the named instance are on the same
server, which is running MSSQL 2000
"Russell Fields" wrote:
> Raffaele,
> server-name is actually linkedserver-name, which may not actually be the
> name of a physical serve. Here is some code from SQL 2005 Books Online
> EXEC sp_addlinkedserver
> @.server='S1_instance1',
> @.srvproduct='',
> @.provider='SQLNCLI',
> @.datasrc='S1\instance1'
> You can see that the instance name is defined in the data source as the
> server 'S1' and the instance '\instance1'. The server name of
> 'S1_instance1' reflects that name, but it could be named
> 'MyFavoriteLinkedServer' or anything else.
> So, then: SELECT * FROM S1_instance1.mydatabase.myowner.MyTable
> RLF
> "Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
> news:BFDA8EDF-1EC1-47E1-A71C-B13B89397DF5@.microsoft.com...
> > hallo it's unclear to me how to address a named instance using a fully
> > qualified name (server-name.database-name.owner-name.object-name)
> > In this syntax, where does the instance name fit?
> >
> > thanks in advance
>
>|||ok linked server solved! the named instance was already present as "remote
server" since was used for a test replica.
Thanks
"Raffaele" wrote:
> i already tried linking the instance, getting error 15028 - the server
> already exists.|||OK, thanks for the update. - RLF
"Raffaele" <Raffaele@.discussions.microsoft.com> wrote in message
news:DA137E75-C8F2-41B3-8B2F-C94344FB3FB4@.microsoft.com...
> ok linked server solved! the named instance was already present as "remote
> server" since was used for a test replica.
> Thanks
> "Raffaele" wrote:
>> i already tried linking the instance, getting error 15028 - the server
>> already exists.
>

Fully qualified name of a table

Hi all,
How can I find the fully qualified name of a table, if all I have is the
table name
I realise that this might be a bit ambigious, but I was wondering.
For example, if I had a table name like employees. It could be in northwind,
or in corporate or both
is there a way to find this out
Thanks
RobertNo easy way, since the object names are not contained in one single table. T
he object names are
contained in a system table or a view inside each database. But you could cr
eate a stored procedure
in which you use a cursor to loop each database and construct dynamic SQL to
pass such a query
against that system table or view. Or you could cheat and use an undocumente
d stored procedure that
dopes just that:
EXEC sp_MSForeachdb 'SELECT * FROM ?.INFORMATION_SCHEMA.TABLES WHERE TABLE_N
AME = ''authors'''
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Robert Bravery" <me@.u.com> wrote in message news:OmHh35UmGHA.1404@.TK2MSFTNGP05.phx.gbl...[
color=darkred]
> Hi all,
> How can I find the fully qualified name of a table, if all I have is the
> table name
> I realise that this might be a bit ambigious, but I was wondering.
> For example, if I had a table name like employees. It could be in northwin
d,
> or in corporate or both
> is there a way to find this out
> Thanks
> Robert
>[/color]|||> How can I find the fully qualified name of a table, if all I have is the
> table name
If all you have is a table name, then you could get 1 or 20 answers (even
within the same database, because you could have dbo.Employees and
someOtherUser.Employees).
Now you are talking about going across databases, that's even more potential
answers. Here is how to find all the tables named 'Employees' in the
databases Northwind and Corporate:
SELECT '[' + TABLE_CATALOG + '].[ + TABLE_SCHEMA + '].[' + TABLE_NAME
FROM NorthWind.INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'Employees'
AND TABLE_TYPE = 'BASE_TABLE'
UNION
SELECT '[' + TABLE_CATALOG + '].[ + TABLE_SCHEMA + '].[' + TABLE_NAME
FROM Corporate.INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'Employees'
AND TABLE_TYPE = 'BASE_TABLE';|||You might try something like:
sp_msforeachdb 'select ''?.'' + rtrim(table_schema) + ''.'' +
rtrim(table_name)
from ?.information_schema.tables where table_name = ''employees'''
--
If you are looking for SQL Server examples check out my Website at
http://www.geocities.com/sqlserverexamples
"Robert Bravery" wrote:

> Hi all,
> How can I find the fully qualified name of a table, if all I have is the
> table name
> I realise that this might be a bit ambigious, but I was wondering.
> For example, if I had a table name like employees. It could be in northwin
d,
> or in corporate or both
> is there a way to find this out
> Thanks
> Robert
>
>|||Try,
create table #t (
tc sysname,
ts sysname,
tn sysname
)
declare @.sql nvarchar(4000)
declare @.tc sysname
declare my_cursor cursor
local
fast_forward
for
select [name]
from master.dbo.sysdatabases
where [name] not in ('master', 'tempdb', 'msdb', 'model')
open my_cursor
while 1 = 1
begin
fetch next from my_cursor into @.tc
if @.@.error != 0 or @.@.fetch_status != 0 break
set @.sql = N'use [' + @.tc + ']; select TABLE_CATALOG, TABLE_SCHEMA,
TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = ''BASE TABLE'''
insert into #t
exec sp_executesql @.sql
end
close my_cursor
deallocate my_cursor
select
*
from
#t as a
where
exists (
select
*
from
#t as b
where
b.ts = a.ts
and b.tn = a.tn
and b.tc != a.tc
)
order by
tn,
tc,
ts
drop table #t
go
AMB
"Robert Bravery" wrote:

> Hi all,
> How can I find the fully qualified name of a table, if all I have is the
> table name
> I realise that this might be a bit ambigious, but I was wondering.
> For example, if I had a table name like employees. It could be in northwin
d,
> or in corporate or both
> is there a way to find this out
> Thanks
> Robert
>
>