Quantcast
Viewing all articles
Browse latest Browse all 31116

SQL Server object overview (tables, index, etc) tutorial

Since I could not find any downloadable PowerBI reports that give insight into objects (like tables, views, indexes etc) in our SQL Server database I made one myself. At the moment it only contains tables, but you can add any objects yourself. I thought I'd share it with you. I cannot find an option to attach the reports so you have to make it yourself. But I'll explain the process and give the code for some views that are needed for the data. You need the rights to deploy and read those views otherwise it won't work. I'm from Holland so you'll see some Dutch language. 

 

This is the report we use. Notice it contains different instances and different databases:

Image may be NSFW.
Clik here to view.
objectoverzicht.PNG


 

For the data you have to make a seperate view in *all* databases and *all* instances you want to show. We use linked servers to other instances, and through those linked servers we connect to these views. In every database we have a schema "beheer" (like "management" in Dutch) where we store these views. So for every database in every instance you have to make this view:

CREATE VIEW [Beheer].[objectoverzicht] AS
SELECT @@SERVICENAME as instance, db_name() as [database], s.Name AS [schema], t.NAME AS tabel, p.rows AS rijen, (SUM (a.total_pages) * 8) / 1024 AS totaal_mb, (SUM (a.used_pages) * 8) / 1024 AS gebruikt_mb FROM sys.tables t INNER JOIN sys.schemas s ON s.schema_id = t.schema_id INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND i.OBJECT_ID > 255 GROUP BY t.Name, s.Name, p.Rows

 

Then you make a "master view" that combines the other ones (note that on the other instances I also made master views) (samengevoegd means something like "combined" in Dutch):

CREATE VIEW [Beheer].[objectoverzicht_samengevoegd]
AS
SELECT *
	FROM Datamart.beheer.objectoverzicht
UNION ALL
SELECT *
	FROM Datastore.beheer.objectoverzicht
UNION ALL
SELECT *
	FROM DWH.beheer.objectoverzicht
UNION ALL
SELECT *
	FROM more.views
UNION
SELECT *
	FROM [linked server 1].metadata.beheer.objectoverzicht_samengevoegd
UNION
SELECT *
	FROM [linked server 2].metadata.beheer.objectoverzicht_samengevoegd

Finally, import the data from the master view into PowerBI and if you are a basic user you can make the reports in no time, there are no special formulas you have to make (well maybe some simple DAX) and the report can be made with the default visualisations. I do recommend using the Chicklet slicer for the buttons.


Viewing all articles
Browse latest Browse all 31116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>