Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Jayasurya_C01
New Member

PowerBI query

I would like to get all database under the SQL server and all the tables under the each database of the server in powerBI like how I can see all data in sql server(SSMS). I just expecting like this format in powerbi. could you please suggest any query or any method to get data like this.

Jayasurya_C01_0-1720606238118.png

@PowerBI

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jayasurya_C01 ,

 

Try below sql code when you connect to sql server database:

 

SELECT 
    d.name AS DatabaseName,
    s.name AS SchemaName,
    t.name AS TableName
FROM 
    sys.databases d
JOIN 
    sys.tables t ON d.database_id = DB_ID(d.name)
JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
ORDER BY 
    d.name, s.name, t.name;

 

vkongfanfmsft_1-1721638695652.png

 

vkongfanfmsft_0-1721638560521.png

 

M code:

let
    Source = Sql.Database("***", "AdventureWorksDW2014", [Query="SELECT #(lf)    d.name AS DatabaseName,#(lf)    s.name AS SchemaName,#(lf)    t.name AS TableName#(lf)FROM #(lf)    sys.databases d#(lf)JOIN #(lf)    sys.tables t ON d.database_id = DB_ID(d.name)#(lf)JOIN #(lf)    sys.schemas s ON t.schema_id = s.schema_id#(lf)ORDER BY #(lf)    d.name, s.name, t.name;#(lf)"])
in
    Source

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Jayasurya_C01 ,

 

Try below sql code when you connect to sql server database:

 

SELECT 
    d.name AS DatabaseName,
    s.name AS SchemaName,
    t.name AS TableName
FROM 
    sys.databases d
JOIN 
    sys.tables t ON d.database_id = DB_ID(d.name)
JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
ORDER BY 
    d.name, s.name, t.name;

 

vkongfanfmsft_1-1721638695652.png

 

vkongfanfmsft_0-1721638560521.png

 

M code:

let
    Source = Sql.Database("***", "AdventureWorksDW2014", [Query="SELECT #(lf)    d.name AS DatabaseName,#(lf)    s.name AS SchemaName,#(lf)    t.name AS TableName#(lf)FROM #(lf)    sys.databases d#(lf)JOIN #(lf)    sys.tables t ON d.database_id = DB_ID(d.name)#(lf)JOIN #(lf)    sys.schemas s ON t.schema_id = s.schema_id#(lf)ORDER BY #(lf)    d.name, s.name, t.name;#(lf)"])
in
    Source

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Jayasurya_C01 , In case you have access to read Information schema, this query can help

 

SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit, yeah its really works and also i have tried this to get a databases but by using this method I can get tables for single database only(by run the query in single database query page). I just need all the database & tables under the sever.(Dynamically)
In three columns i need to view all the details of the server. 
thanks for your help 🙂

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.