Avatar of PeterBaileyUk
PeterBaileyUk
 asked on

sql server query

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)
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
John Tsioumpris

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...
PeterBaileyUk

ASKER
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 Tsioumpris

Does your account has permissions to use this database...?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
PeterBaileyUk

ASKER
objects
here is a screenshot of the structure
PeterBaileyUk

ASKER
yes I have the permissions as I created both dbs
ASKER CERTIFIED SOLUTION
John Tsioumpris

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
John Tsioumpris

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...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
PeterBaileyUk

ASKER
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 Tsioumpris

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
PeterBaileyUk

ASKER
thank you the tool you suggested got me to the correct 'way'

use ClientData

SELECT * FROM Dictionary.dbo.TblCurrentWords
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
John Tsioumpris

So i guess it was case sensitive issue...
Vitor Montalvão

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

Should be 'a' instead of 'e'.