SQL Server Collection Inventory Script -2

Hi,

You want to learn all Inventory of SQL Server when you connect to SQL Server database for the first time.

 

This SQL Server Database Inventory consist of following informations.

  • Machine Name
  • Instance Name
  • Total Database Log Size
  • Total Database Log Used
  • Total Database Datafile size
  • Product version
  • Product level
  • SQL Server Edition
  • Owner

 

Query is like following, it will make your job very simplify when you connect to any SQL Server database for the first time.

 

select getdate() Date_Collected
	  ,serverproperty('MachineName') 'Machine_Name'
	  ,isnull(serverproperty('InstanceName'),'mssqlserver') 'Instance_Name'
	  ,@@SERVERNAME 'Sql_Server_Name'
	  ,SERVERPROPERTY('productversion') Product_Version 
	  ,SERVERPROPERTY ('productlevel') Product_Level 
	  ,SERVERPROPERTY ('edition') 'Edition'
	  ,d.name 'database_name'
	  ,suser_sname(d.owner_sid) 'owner'
	  ,ls.cntr_value as [log_size_kb]
	  ,lu.cntr_value as [log_used_kb]
	  ,lp.cntr_value as [percent_log_used]
	  ,ds.cntr_value as [data_files_size_kb]
from sys.databases d
	 left outer join sys.dm_os_performance_counters as lu on lu.instance_name=d.name and lu.counter_name like N'Log File(s) Used Size (KB)%'
	 left outer join sys.dm_os_performance_counters as ls on ls.instance_name=d.name and ls.counter_name like N'Log File(s) Size (KB)%' and ls.cntr_value > 0
	 left outer join sys.dm_os_performance_counters as lp on lp.instance_name=d.name and lp.counter_name like N'Percent Log Used%'
	 left outer join sys.dm_os_performance_counters as ds on ds.instance_name=d.name and ds.counter_name like N'Data File(s) Size (KB)%'
order by d.name;

 

 

 

Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.

https://ittutorial.org/sql-server-tutorials-microsoft-database-for-beginners/

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *