如何以SQL指令作Performance Tuning
一般而言SQL 的Performance Tuning 可使用SQL Profiler , 但是如果要調教的機器上SQL Server上並未安裝SQL Profiler 或使用者不會使用SQL Profiler時, 則可用指令的方式執行. 本案例的狀況是: 對方的機器是SQL Server 2008 且未安裝SQL Profiler. 筆者手上的機器只有SQL Server 2005 , 但有安裝SQL Profiler . 1.建立SQL Profiler 的指令檔. 1.1 開啟SQL Server 2005 , 進入SQL Profiler. 1.2. 選擇追蹤的事件 可設定常用的事件, 包括 RFC:Completed, SP:StmtCompleted,SQL:BatchCompleted 1.3.設定資料行篩選, 可設定篩選條件例如針對Reads 的次數大於1000以上才記錄. 1.4. 設定完成後, 點選執行後, 在將其停止, 並匯出指令檔. 1.5. 產生的SQL 如下: (若上述的追蹤項目可用, 可直接使用以下的SQL 追蹤) -- Create a Queue declare @rc int declare @TraceID int declare @maxfilesize bigint set @maxfilesize = 5 -- Please replace the text InsertFileNameHere, with an appropriate -- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension -- will be appended to the filename automatically. If you are writing from -- remote server to local drive, please use UNC path and make sure server has -- write acce...