如题,觉得探查器的功能很强大,不知道谁能给个小小的sql+具体的操作,
小小的示范一下,谢谢

解决方案 »

  1.   

    打开探查器,连接到一个sqlserver实例,新建一个跟踪,可以看到当前选定实例进行的操作。
    当然,你还可以在这个跟踪里进行过滤,应用:在一些排错的时候很有用。打个比方:c#里执行了:string sql=@"declare @id int ;
    select @id=max(id) from tb;
    select * into # from tx where id=@id and v=@v
    select * from #
    ...";
    之类这样的语句:
    @id是sql变量,@v是c# 中 sqlcommand
    当写出这样的语句时,提示#不存,这时就很难查错。当然,对c#和sqlserver比较熟悉的人想一下就知道为什么会报错,原因就是 c#中传参方式执行的语句在sql端 是转为sql_executesql执行的, 这样就引发了临时表生命周期的问题, sql_executesql内部生成了临时表#,而select * from #却是在其外部,所以会报错。不了解的人,在这里很难走过去,除了换其它方式写。 这时打开事件探查器一看,仔细一想,就知道错误原因了。
      

  2.   

    Start>All Programs>Microsoft SQL Server 2005>Performance Tools>SQL Server Profile>File>New TraceExample:
    1. Launch SQL Server Profiler.
    2. From the File menu, choose New Trace.
    3. Connect to your SQL Server instance.
    4. On the General tab, specify the following options:
    A. Name of the trace
    B. Blank template
    C. Save to file and use the default file name
    D. Maximum file size of 50 MB
    E. Enable file rollover
    5. On the Events tab, select the check boxes for the following events:
    A. SQL:BatchCompleted
    B. RPC:Completed
    C. Showplan XML
    6. Specify the following additional data columns:
    A. CPU
    B. Reads
    C. Writes
    D. Start Time
    E. End Time
    7. Run the trace.
    8. Using SSMS, execute several queries against the AdventureWorks database and
    observe what is captured in Profiler.
    9. In SQL Server Profiler, stop the trace. Close Profiler.
      

  3.   

    Start>All Programs>Microsoft SQL Server 2005>Performance Tools>SQL Server Profile>File>New TraceExample:
    1. Launch SQL Server Profiler.
    2. From the File menu, choose New Trace.
    3. Connect to your SQL Server instance.
    4. On the General tab, specify the following options:
    A. Name of the trace
    B. Blank template
    C. Save to file and use the default file name
    D. Maximum file size of 50 MB
    E. Enable file rollover
    5. On the Events tab, select the check boxes for the following events:
    A. SQL:BatchCompleted
    B. RPC:Completed
    C. Showplan XML
    6. Specify the following additional data columns:
    A. CPU
    B. Reads
    C. Writes
    D. Start Time
    E. End Time
    7. Run the trace.
    8. Using SSMS, execute several queries against the AdventureWorks database and
    observe what is captured in Profiler.
    9. In SQL Server Profiler, stop the trace. Close Profiler.