We help IT Professionals succeed at work.

sql server query

106 Views
Last Modified: 2018-01-17
What s the query syntax to query a table from another db.  am currently n a db named ClentData where some tables resse but  also want to get to a table n a bd called dctonery(sorry lost a letter on my keyboard)
Comment
Watch Question

John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Try this
SELECT * FROM DATABASENAME.SCHEMA.TABLENAME

Open in new window

so in your case should be
SELECT * FROM dctonery.dbo.n

Open in new window

The schema dbo is just an assumption because its very common...

Author

Commented:
I think this is what you meant but it says it cannot find the object name

use clientdata
go

SELECT * FROM dictionery.[dbo].[TblCurrentWords]

Open in new window

John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Does your account has permissions to use this database...?

Author

Commented:
objects
here is a screenshot of the structure

Author

Commented:
yes I have the permissions as I created both dbs
IT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
As a workaround because maybe something is not as it seems ....go to DevART and download dbForge SQL Complete, v5.5 Express...after you install this you will have intellisense when you are doing queries and it will show you the proper syntax...

Author

Commented:
this worked:

so I guess that proves the permissions

--use clientdata
--go

--SELECT * FROM dictionery.[dbo].[TblCurrentWords]

use Dictionary


SELECT * FROM [dbo].[TblCurrentWords]

Open in new window

John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
How about right clicking your Dictionary database and Refresh
EDIT: have you tried to match exactly the case ...i see Dictionary working but...dictionary is lowercase
maybe your server collation is case sensitive...so lowercase <> uppercase

Author

Commented:
thank you the tool you suggested got me to the correct 'way'

use ClientData

SELECT * FROM Dictionary.dbo.TblCurrentWords
John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
So i guess it was case sensitive issue...
Vitor Montalv√£oIT Engineer
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
You just got a typo in your select:
SELECT * FROM dictionery.[dbo].[TblCurrentWords]

Should be 'a' instead of 'e'.