SQL Query against multiple databases

I need to write a query, that will be used as a view to select all columns from the same named table in each of my databases into a single result panel.
vpnsol123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JesterTooCommented:
If this is Sql Server then you can use multi-part names that are capable of referencing objects from different schemas, different databases and even different servers.

See this link for more info...   https://docs.microsoft.com/en-us/sql/t-sql/language-elements/transact-sql-syntax-conventions-transact-sql
0
vpnsol123Author Commented:
Thank you for the above.  What I am looking to do is to write a single query the will read the database names out of the sys_databases table and run the query against each of them.  Sorry, that was not clear at all in my initial post.
0
JesterTooCommented:
You will need to use the System Catalog Views to access data contained in the master database.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SharathData EngineerCommented:
try this. Replace Your_Table with your actual table name
DECLARE @Result TABLE (DB_NAME VARCHAR(100), TABLE_NAME VARCHAR(100), COLUMN_NAME VARCHAR(100))
INSERT @Result
EXEC sp_Msforeachdb "USE ?; SELECT '?' DB_NAME, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Your_Table'"
SELECT * FROM @Result

Open in new window

0
vpnsol123Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.