SQL Server Collection Inventory Script -3

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
  • SQL Server Name
  • Database Name
  • Owner
  • Compatibility
  • Collation Name
  • IS_auto_close_on
  • IS_auto_shrink_on
  • IS_in_standby
  • Page_verify_option_desc
  • State
  • IS_auto_create_stats_on
  • IS_auto_update_stats_on
  • IS_auto_update_stats_async_on
  • Total Database Log Size
  • Total Database Log Used
  • Total Database Datafile size

 

 

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

 

select 
	  serverproperty('MachineName') 'machine_name'
	  ,isnull(serverproperty('InstanceName'),'mssqlserver') 'instance_name'
	  ,@@SERVERNAME 'sql_server_name'
	  ,d.name 'database_name'
	  ,suser_sname(d.owner_sid) 'owner'
	  ,d.compatibility_level
	  ,d.collation_name
	  ,d.is_auto_close_on
	  ,d.is_auto_shrink_on
	  ,d.state_desc
	  ,d.snapshot_isolation_state
	  ,d.is_read_committed_snapshot_on
	  ,d.recovery_model_desc
	  ,d.is_auto_create_stats_on
	  ,d.is_auto_update_stats_on
	  ,d.is_auto_update_stats_async_on
	  ,d.is_in_standby
	  ,d.page_verify_option_desc
	  ,d.log_reuse_wait_desc
	  ,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 file(s) size (kb)]
from sys.databases d
	 inner 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)%'
	 inner 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
	 inner join sys.dm_os_performance_counters as lp on lp.instance_name=d.name and lp.counter_name like N'Percent Log Used%'
	 inner 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

 

 

Mehmet Salih Deveci

I am Founder of 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 mehmetsalih.deveci@outlook.com. -                                                                                                                                                                                                                                                 - Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  mehmetsalih.deveci@outlook.com a mail atabilirsiniz.

One thought on “SQL Server Collection Inventory Script -3

  • May 17, 2019 at 10:50 am
    Permalink

    That is the fitting blog for anybody who needs to seek out out about this topic. You understand so much its virtually hard to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a subject thats been written about for years. Nice stuff, just great!

    Reply