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

Query Multiple databases

 
   Database Forums (Home) -> MSEQ RSS
Next:  Table field name change propogate to queries/repo..  
Author Message
K

External


Since: Oct 29, 2008
Posts: 1



(Msg. 1) Posted: Wed Oct 29, 2008 10:35 am
Post subject: Query Multiple databases
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

How do I reference tables in different databases in a query? I have tried
database name.table name.field name and that hasn't worked.

TIA,

Kim

 >> Stay informed about: Query Multiple databases 
Back to top
Login to vote
Russell Fields

External


Since: Feb 21, 2007
Posts: 457



(Msg. 2) Posted: Wed Oct 29, 2008 4:43 pm
Post subject: Re: Query Multiple databases [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Kim,

It is: DatabaseName.SchemaName.TableName.ColumnName

You missed the schema (often "dbo") which is also part of the name.

Although, if you use an alias for the table in the code, you would never see
all four of these names together. Instead it would look like:

SELECT Local.KeyColumn, Remote.ColumnName
From dbo.MyLocalTable AS Local
JOIN DatabaseName.SchemaName.TableName AS Remote
ON Local.KeyColumn = Remote.KeyColumn

RLF

"K" wrote in message

> How do I reference tables in different databases in a query? I have tried
> database name.table name.field name and that hasn't worked.
>
> TIA,
>
> Kim

 >> Stay informed about: Query Multiple databases 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Run same query against multiple tables - Hi all, Is there a way to quickly run an sql query against all the tables in a database? or will I have to simply write a line for each table? I have 100+ tables where I want to delete rows from from them where ID= (a particular id). Thanks Gav

Query returning multiple rows - Hi, I have a query that returns back rows that have multiple entries for a given UniqueID. I want the query to be expanded so that it then only returns 1 of the multiple rows based on the maximum date. Thefore, my return set looks like this: ..

Doing multiple joins on one table - I have those Tables: CREATE TABLE GameYellows( id INT NOT NULL AUTO_INCREMENT, AddedDate DATETIME NOT NULL, Player_ID INT NOT NULL, ) CREATE TABLE GameReds( id INT NOT NULL AUTO_INCREMENT, AddedDate DATETIME NOT NULL, Player_ID INT NOT NULL, ) ...

Insert Multiple Rows into a Table Without Using Select - Hi. I want to insert 4 rows into a SQL table. Can I do this without using 4 Insert statements? This is my SQL statement: Insert Into MyTable Values (1,2) (3,4) (5,6)...

query - Hi, I have some models that have hyhen in between. e.g.1200LD-VCD, abc-1234 May I know how to remove the hyhen. Thank you
   Database Forums (Home) -> MSEQ 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 ]