{"id":6366,"date":"2019-03-11T07:47:14","date_gmt":"2019-03-11T07:47:14","guid":{"rendered":"https:\/\/ittutorial.org\/?p=6366"},"modified":"2019-11-28T07:02:00","modified_gmt":"2019-11-28T07:02:00","slug":"sql-server-performance-top-cpu-query-2","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/sql-server-performance-top-cpu-query-2\/","title":{"rendered":"SQL Server Performance TOP CPU Query -2"},"content":{"rendered":"<p>Hi,<\/p>\n<p>If you got slowness complaint from customer,\u00a0 you need to monitor SQL Server Instance and database which sql is consuming a lots of resource.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6253\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-top_query.png\" alt=\"\" width=\"2236\" height=\"494\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-top_query.png 2236w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-top_query-300x66.png 300w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-top_query-768x170.png 768w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/sql-server-top_query-1024x226.png 1024w\" sizes=\"auto, (max-width: 2236px) 100vw, 2236px\" \/><\/p>\n<p><!--more--><\/p>\n\n<p>&nbsp;<\/p>\n<p>SQL Server DBA should monitor database everytime and if there are many sqls which is running long execution time or\u00a0consuming a lots of CPU resource then it should be reported to the developer and developer and dba should examine these sqls.<\/p>\n<p>&nbsp;<\/p>\n<p>You can find TOP CPU queries in SQL Server database with following query.<\/p>\n<p>&nbsp;<\/p>\n<pre>SELECT TOP 50\r\n    ObjectName          = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid)\r\n    ,TextData           = qt.text\r\n    ,DiskReads          = qs.total_physical_reads   -- The worst reads, disk reads\r\n    ,MemoryReads        = qs.total_logical_reads    --Logical Reads are memory reads\r\n    ,Executions         = qs.execution_count\r\n    ,TotalCPUTime       = qs.total_worker_time\r\n    ,AverageCPUTime     = qs.total_worker_time\/qs.execution_count\r\n    ,DiskWaitAndCPUTime = qs.total_elapsed_time\r\n    ,MemoryWrites       = qs.max_logical_writes\r\n    ,DateCached         = qs.creation_time\r\n    ,DatabaseName       = DB_Name(qt.dbid)\r\n    ,LastExecutionTime  = qs.last_execution_time\r\n FROM sys.dm_exec_query_stats AS qs\r\n CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt\r\n ORDER BY qs.total_worker_time DESC;\r\n\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\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, If you got slowness complaint from customer,\u00a0 you need to monitor SQL Server Instance and database which sql is consuming a lots of resource.<\/p>\n","protected":false},"author":1,"featured_media":6253,"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":[2376,2377,1028,1031,1600,1610,2231,2243,2238,2237,2240,2239,2241,2242,2230,2229],"class_list":["post-6366","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-sql-scripts","category-sql-server-2","category-sql-server-dba-scripts","tag-hi","tag-if-you-got-slowness-complaint-from-customer","tag-mehmet-deveci","tag-mehmet-salih-deveci","tag-sql-server-2012","tag-sql-server-2014","tag-sql-server-2019","tag-sql-server-performance-scripts","tag-sql-server-performance-top-cpu-query","tag-sql-server-select-inventory","tag-sql-server-top-cpu","tag-sql-server-top-cpu-query","tag-sql-server-top-queries","tag-sql-server-top-query","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-top_query.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6366","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=6366"}],"version-history":[{"count":2,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6366\/revisions"}],"predecessor-version":[{"id":12959,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6366\/revisions\/12959"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/6253"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=6366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=6366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=6366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}