我知道有很多话题,但是我认为这很具体。我得到用于审计目的的当前代码:
import pandas as pd
import pyodbc
query = """
--Top 50 high total CPU Queries
SELECT TOP 50
'High CPU Queries' as Type,
serverproperty('machinename') as 'Server Name',
isnull(serverproperty('instancename'),serverproperty('machinename')) as 'Instance Name',
COALESCE(DB_NAME(qt.dbid),
DB_NAME(CAST(pa.value as int)),
'Resource') AS DBNAME,
qs.execution_count as [Execution Count],
qs.total_worker_time/1000 as [Total CPU Time],
(qs.total_worker_time/1000)/qs.execution_count as [Avg CPU Time],
qs.total_elapsed_time/1000 as [Total Duration],
(qs.total_elapsed_time/1000)/qs.execution_count as [Avg Duration],
qs.total_physical_reads as [Total Physical Reads],
qs.total_physical_reads/qs.execution_count as [Avg Physical Reads],
qs.total_logical_reads as [Total Logical Reads],
qs.total_logical_reads/qs.execution_count as [Avg Logical …Run Code Online (Sandbox Code Playgroud)