2022年用SQL语句来建立跟踪的问题SQL server]教程.docx
2022年用SQL语句来建立跟踪的问题SQL server教程下面是我用SQL的事务探察器设置跟踪,并生成的SQL脚本现在有几个问题:1.这个跟踪不会产生数据,用:select*from:fn_trace_getinfo(1)可以看到状态是在运行,但c:test.trc始终是空文件2.在事务探察器中设置筛选时,ObjectType的说明是对应sysobjects表的type列,该列是字符型,但我输入字符时要求是数字,这个数字从那里查? 3.假如只产生对insert,update,delete语句胜利的跟踪事务应当如何设置呢?在事务探察器中无相关设置,用语句设置的话只找到事务号28,在执行SELECT、INSERT或UPDATE语句之前发生 4.用事务探察器建立的跟踪,可以将跟踪结果保存到表中,但我下面生成的SQL脚本却不支持这个功能-*/*/*Createdby:SQLProfiler*/*Date:2022/06/1916:50:05*/*/-CreateaQueuedeclarercintdeclareTraceIDintdeclaremaxfilesizebigintsetmaxfilesize=5-PleasereplacethetextInsertFileNameHere,withanappropriate-filenameprefixedbyapath,e.g.,c:MyFolderMyTrace.The.trcextension-willbeappendedtothefilenameautomatically.Ifyouarewritingfrom-remoteservertolocaldrive,pleaseuseUNCpathandmakesureserverhas-writeaccesstoyournetworkshareexecrc=sp_trace_createTraceIDoutput,0,Nc:test,maxfilesize,NULLif(rc!=0)gotoerror-ClientsideFileandTablecannotbescripted-WritingtoatableisnotsupportedthroughtheSPs-Settheeventsdeclareonbitseton=1execsp_trace_seteventTraceID,12,1,onexecsp_trace_seteventTraceID,12,12,onexecsp_trace_seteventTraceID,12,14,on-SettheFiltersdeclareintfilterintdeclarebigintfilterbigintexecsp_trace_setfilterTraceID,10,0,7,NSQLProfilersetintfilter=100execsp_trace_setfilterTraceID,22,0,4,intfiltersetintfilter=1execsp_trace_setfilterTraceID,23,1,0,intfilterexecsp_trace_setfilterTraceID,35,1,6,Npubs-Setthetracestatustostartexecsp_trace_setstatusTraceID,1-displaytraceidforfuturereferencesselectTraceID=TraceIDgotofinisherror:selectErrorCode=rcfinish:go