{"id":6334,"date":"2019-03-08T13:23:48","date_gmt":"2019-03-08T13:23:48","guid":{"rendered":"https:\/\/ittutorial.org\/?p=6334"},"modified":"2019-11-28T07:05:05","modified_gmt":"2019-11-28T07:05:05","slug":"sql-server-collection-inventory-script-2","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/sql-server-collection-inventory-script-2\/","title":{"rendered":"SQL Server Collection Inventory Script -2"},"content":{"rendered":"<p>Hi,<\/p>\n<p>You want to learn all Inventory of SQL Server when you connect to SQL Server database for the first time.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6247\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server.png\" alt=\"\" width=\"466\" height=\"383\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server.png 466w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-300x247.png 300w\" sizes=\"auto, (max-width: 466px) 100vw, 466px\" \/><\/p>\n<p><!--more--><\/p>\n\n<p>&nbsp;<\/p>\n<p>This SQL Server Database Inventory consist of following informations.<\/p>\n<ul>\n<li>Machine Name<\/li>\n<li>Instance Name<\/li>\n<li>Total Database Log Size<\/li>\n<li>Total Database Log Used<\/li>\n<li>Total Database Datafile size<\/li>\n<li>Product version<\/li>\n<li>Product level<\/li>\n<li>SQL Server Edition<\/li>\n<li>Owner<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<p>Query is like following,\u00a0it will make your job very simplify when you connect to any SQL Server database for the first time.<\/p>\n<p>&nbsp;<\/p>\n<pre>select getdate() Date_Collected\r\n\t  ,serverproperty('MachineName') 'Machine_Name'\r\n\t  ,isnull(serverproperty('InstanceName'),'mssqlserver') 'Instance_Name'\r\n\t  ,@@SERVERNAME 'Sql_Server_Name'\r\n\t  ,SERVERPROPERTY('productversion') Product_Version \r\n\t  ,SERVERPROPERTY ('productlevel') Product_Level \r\n\t  ,SERVERPROPERTY ('edition') 'Edition'\r\n\t  ,d.name 'database_name'\r\n\t  ,suser_sname(d.owner_sid) 'owner'\r\n\t  ,ls.cntr_value as [log_size_kb]\r\n\t  ,lu.cntr_value as [log_used_kb]\r\n\t  ,lp.cntr_value as [percent_log_used]\r\n\t  ,ds.cntr_value as [data_files_size_kb]\r\nfrom sys.databases d\r\n\t 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)%'\r\n\t 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 &gt; 0\r\n\t 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%'\r\n\t 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)%'\r\norder by d.name;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><span style=\"color: #ff0000;\">Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.<\/span><\/h4>\n<p><a href=\"https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/\">https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, You want to learn all Inventory of SQL Server when you connect to SQL Server database for the first time.<\/p>\n","protected":false},"author":1,"featured_media":6247,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3828,2227,3827],"tags":[1028,1031,1600,1610,2231,2228,2233,2232,2237,2236,2323,2324,2234,2235,2230,2229],"class_list":["post-6334","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-sql-scripts","category-sql-server-2","category-sql-server-dba-scripts","tag-mehmet-deveci","tag-mehmet-salih-deveci","tag-sql-server-2012","tag-sql-server-2014","tag-sql-server-2019","tag-sql-server-collection-inventory-script","tag-sql-server-instance-name","tag-sql-server-inventory-script","tag-sql-server-select-inventory","tag-sql-server-select-machine-name","tag-sql-server-sys-databases","tag-sql-server-sys-dm_os_performance_counters","tag-sql-server-total-database-datafile-size","tag-sql-server-total-database-log-size","tag-sql-server-useful-query","tag-sql-server-useful-script"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=6334"}],"version-history":[{"count":2,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6334\/revisions"}],"predecessor-version":[{"id":12967,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6334\/revisions\/12967"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/6247"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=6334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=6334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=6334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}