sqlserver 效能分析報表

2021-09-08 02:23:04 字數 2435 閱讀 2368

eclare

@user_id int,

@killcmd varchar(100),

@wait_time int

-- 設定空閒時間

set @wait_time = 2;

-- 根據選擇條件,選擇出應該取消的程序

declare cur_lock cursor for

select spid

from master..sysprocesses

where

datediff(minute, last_batch, getdate()) > @wait_time

and blocked = 0

and spid in

(select blocked

from master..sysprocesses);

-- 取消所有選擇出的程序。

open cur_lock;

fetch next from cur_lock into @user_id;

while @@fetch_status = 0

begin

set @killcmd = 'kill ' + cast(@user_id as varchar)

execute (@killcmd);

fetch next from cur_lock into @user_id;

end;

close cur_lock;

deallocate cur_lock;

--查詢鎖資訊

select * from sys.dm_tran_locks

--查詢newbjx資料庫中表的數量

select count(*) from newbjx..sysobjects where type='u' and status>=0

declare

@user_id int,

@killcmd varchar(100),

@wait_time int

-- 設定空閒時間

set @wait_time = 2;

-- 根據選擇條件,選擇出應該取消的程序

declare cur_lock cursor for

select spid

from master..sysprocesses

where

datediff(minute, last_batch, getdate()) > @wait_time

and blocked = 0

and spid in

(select blocked

from master..sysprocesses);

-- 取消所有選擇出的程序。

open cur_lock;

fetch next from cur_lock into @user_id;

while @@fetch_status = 0

begin

set @killcmd = 'kill ' + cast(@user_id as varchar)

execute (@killcmd);

fetch next from cur_lock into @user_id;

end;

close cur_lock;

deallocate cur_lock;

--下面的示例返回使會話 id 與某一 windows 執行緒 id 相關聯的資訊。

--可以在 windows 效能監視器中監視該執行緒的效能。該查詢不返回當前正在休眠的會話 id。

select stasks.session_id, sthreads.os_thread_id

from sys.dm_os_tasks as stasks

inner join sys.dm_os_threads as sthreads

on stasks.worker_address = sthreads.worker_address

where stasks.session_id is not null

order by stasks.session_id;

go set statistics io on

set statistics time on

select top 50 sum(qs.total_worker_time)/1000 as total_cpu_time,

sum(qs.execution_count)/1000 as total_execution_count,

count(*) as number_of_statements,

qs.plan_handle,qs.sql_handle

from sys.dm_exec_query_stats qs

group by qs.plan_handle

order by sum(qs.total_worker_time) desc

SQL Server 報表服務

報表服務 reporting services,ssrs 提供了各種現成可用的工具和服務,幫助資料庫管理員建立,部署和管理單位的報表,並提供了能夠擴充套件和自定義報表功能的程式設計功能。每乙個事務都有生命週期,報表也是如此。每個報表的的生存週期都包括報表建立 報表管理和報表傳輸三個活動過程。ssrs...

sqlserver分頁查詢語句效能分析

目的 通過三種不同的分頁查詢語句的寫法來比較其效能。環境 windows server 2003 sp2 sqlserver2008。資料準備 100萬條資料。說明 下列sql語句中 pagesize表明每頁記錄條數 pageindex表示頁碼 table表示表明,id表示table表中的主鍵。方法...

sql server效能分析 索引使用效率評估

使用很少的索引排在最先 declare dbid int select dbid db id select objectname object name s.object id s.object id,indexname i.name,i.index id user seeks,user scans...