You are on page 1of 13

sp_trace_setevent [ @traceid = ] trace_id , [ @eventid = ] event_id , [ @columnid = ] column_id , [ @on = ] on Arguments [ @traceid = ] trace_id Is the ID of the trace to be modified.

trace_id is int, with no default. The user employs this trace_id value to identify, modify, and control the trace. [ @eventid = ] event_id Is the ID of the event to turn on. event_id is int, with no default. This table lists the events that can be added to or removed from a trace. Event Event name number 0-9 Reserved 10 11 12 13 14 15 16 17 18 RPC:Completed RPC:Starting SQL:BatchCompleted SQL:BatchStarting Audit Login Audit Logout Attention ExistingConnection Audit Server Starts and Stops DTCTransaction Audit Login Failed EventLog ErrorLog Lock:Released Lock:Acquired Lock:Deadlock Description Reserved Occurs when a remote procedure call (RPC) has completed. Occurs when an RPC has started. Occurs when a Transact-SQL batch has completed. Occurs when a Transact-SQL batch has started. Occurs when a user successfully logs in to SQL Server. Occurs when a user logs out of SQL Server. Occurs when attention events, such as client-interrupt requests or broken client connections, happen. Detects all activity by users connected to SQL Server before the trace started. Occurs when the SQL Server service state is modified. Tracks Microsoft Distributed Transaction Coordinator (MS DTC) coordinated transactions between two or more databases. Indicates that a login attempt to SQL Server from a client failed. Indicates that events have been logged in the Windows application log. Indicates that error events have been logged in the SQL Server error log. Indicates that a lock on a resource, such as a page, has been released. Indicates acquisition of a lock on a resource, such as a data page. Indicates that two concurrent transactions have deadlocked each other by trying to obtain incompatible locks on resources the other transaction owns.

19 20 21 22 23 24 25

26

Lock:Cancel

Indicates that the acquisition of a lock on a resource has been canceled (for example, due to a deadlock). Indicates that a request for a lock on a resource, such as a page, has timed out due to another transaction holding a blocking lock on the required resource. Time-out is determined by the @@LOCK_TIMEOUT function, and can be set with the SET LOCK_TIMEOUT statement.

27

Lock:Timeout

28 29-31 32 33 34 35 36 37 38 39 40 41 42 43 44

Degree of Parallelism Event Occurs before a SELECT, INSERT, or UPDATE statement is executed. (7.0 Insert) Reserved Reserved Exception SP:CacheMiss SP:CacheInsert SP:CacheRemove SP:Recompile SP:CacheHit Deprecated SQL:StmtStarting SQL:StmtCompleted SP:Starting SP:Completed SP:StmtStarting Use Event 28 instead. Reserved Indicates that an exception has occurred in SQL Server. Indicates when a stored procedure is not found in the procedure cache. Indicates when an item is inserted into the procedure cache. Indicates when an item is removed from the procedure cache. Indicates that a stored procedure was recompiled. Indicates when a stored procedure is found in the procedure cache. Deprecated Occurs when the Transact-SQL statement has started. Occurs when the Transact-SQL statement has completed. Indicates when the stored procedure has started. Indicates when the stored procedure has completed. Indicates that a Transact-SQL statement within a stored procedure has started executing. Indicates that a Transact-SQL statement within a stored procedure has finished executing. Indicates that an object has been created, such as for CREATE INDEX, CREATE TABLE, and CREATE DATABASE statements. Indicates that an object has been deleted, such as in DROP INDEX and DROP TABLE statements.

45

SP:StmtCompleted

46

Object:Created

47 48 49 50 51

Object:Deleted Reserved Reserved SQL Transaction Scan:Started

Tracks Transact-SQL BEGIN, COMMIT, SAVE, and ROLLBACK TRANSACTION statements. Indicates when a table or index scan has started.

52 53 54

Scan:Stopped CursorOpen TransactionLog

Indicates when a table or index scan has stopped. Indicates when a cursor is opened on a Transact-SQL statement by ODBC, OLE DB, or DB-Library. Tracks when transactions are written to the transaction log. Indicates that a hashing operation (for example, hash join, hash aggregate, hash union, and hash distinct) that is not processing on a buffer partition has reverted to an alternate plan. This can occur because of recursion depth, data skew, trace flags, or bit counting.

55

Hash Warning

56-57 58 59

Reserved Auto Stats Lock:Deadlock Chain Indicates an automatic updating of index statistics has occurred. Produced for each of the events leading up to the deadlock. Indicates that a finer-grained lock has been converted to a coarser-grained lock (for example, a page lock escalated or converted to a TABLE or HoBT lock). Indicates that an OLE DB error has occurred.

60

Lock:Escalation

61 62-66 67 68

OLE DB Errors Reserved Execution Warnings

Indicates any warnings that occurred during the execution of a SQL Server statement or stored procedure.

Showplan Text (Unencoded) Displays the plan tree of the Transact-SQL statement executed. Indicates sort operations that do not fit into memory. Does not include sort operations involving the creating of indexes; only sort operations within a query (such as an ORDER BY clause used in a SELECT statement). Indicates when a cursor on a Transact-SQL statement is prepared for use by ODBC, OLE DB, or DB-Library. ODBC, OLE DB, or DB-Library has prepared a Transact-SQL statement or statements for use. ODBC, OLE DB, or DB-Library has executed a prepared Transact-SQL statement or statements. ODBC, OLE DB, or DB-Library has unprepared (deleted) a prepared TransactSQL statement or statements. A cursor previously prepared on a Transact-SQL statement by ODBC, OLE DB, or DB-Library is executed. A cursor opened on a Transact-SQL statement by ODBC or DB-Library has been recompiled either directly or due to a schema change. Triggered for ANSI and non-ANSI cursors.

69

Sort Warnings

70

CursorPrepare

71

Prepare SQL

72

Exec Prepared SQL

73

Unprepare SQL

74

CursorExecute

75

CursorRecompile

76

CursorImplicitConversion

A cursor on a Transact-SQL statement is converted by SQL Server from one type to another.

Triggered for ANSI and non-ANSI cursors. 77 CursorUnprepare A prepared cursor on a Transact-SQL statement is unprepared (deleted) by ODBC, OLE DB, or DB-Library. A cursor previously opened on a Transact-SQL statement by ODBC, OLE DB, or DB-Library is closed. Column statistics that could have been useful for the optimizer are not available. Query that has no join predicate is being executed. This could result in a longrunning query. SQL Server memory usage has increased or decreased by either 1 megabyte (MB) or 5 percent of the maximum server memory, whichever is greater. Event data defined by the user. Indicates that a data file was extended automatically by the server. Indicates that a log file was extended automatically by the server. Indicates that a data file was shrunk automatically by the server. Indicates that a log file was shrunk automatically by the server. Displays the query plan tree of the SQL statement from the query optimizer. Note that the TextData column does not contain the Showplan for this event. Displays the query plan with full compile-time details of the SQL statement executed. Note that the TextData column does not contain the Showplan for this event. Displays the query plan with full run-time details of the SQL statement executed. Note that the TextData column does not contain the Showplan for this event.

78

CursorClose

79

Missing Column Statistics

80

Missing Join Predicate

81 82-91 92 93 94 95 96

Server Memory Change User Configurable (0-9) Data File Auto Grow Log File Auto Grow Data File Auto Shrink Log File Auto Shrink Showplan Text

97

Showplan All

98

Showplan Statistics Profile

99 100 101 102

Reserved RPC Output Parameter Reserved Audit Statement GDR Event Occurs every time a GRANT, DENY, REVOKE for a statement permission is issued by any user in SQL Server. Occurs every time a GRANT, DENY, REVOKE for an object permission is issued by any user in SQL Server. Occurs when a SQL Server login is added or removed; for sp_addlogin and sp_droplogin. Occurs when a Windows login right is added or removed; for sp_grantlogin, sp_revokelogin, and sp_denylogin. Produces output values of the parameters for every RPC.

103

Audit Object GDR Event

104

Audit AddLogin Event

105 106

Audit Login GDR Event

Audit Login Change Property Occurs when a property of a login, except passwords, is modified; for

Event Audit Login Change Password Event Audit Add Login to Server Role Event

sp_defaultdb and sp_defaultlanguage. Occurs when a SQL Server login password is changed. Passwords are not recorded. Occurs when a login is added or removed from a fixed server role; for sp_addsrvrolemember, and sp_dropsrvrolemember. Occurs when a login is added or removed as a database user (Windows or SQL Server) to a database; for sp_grantdbaccess, sp_revokedbaccess, sp_adduser, and sp_dropuser. Occurs when a login is added or removed as a database user (fixed or userdefined) to a database; for sp_addrolemember, sp_droprolemember, and sp_changegroup. Occurs when a login is added or removed as a database user to a database; for sp_addrole and sp_droprole. Occurs when a password of an application role is changed.

107

108

109

Audit Add DB User Event

110

Audit Add Member to DB Role Event

111

Audit Add Role Event Audit App Role Change Password Event

112

113

Audit Statement Permission Occurs when a statement permission (such as CREATE TABLE) is used. Event Audit Schema Object Access Occurs when an object permission (such as SELECT) is used, both successfully Event or unsuccessfully. Audit Backup/Restore Event Occurs when a BACKUP or RESTORE command is issued. Audit DBCC Event Audit Change Audit Event Audit Object Derived Permission Event OLEDB Call Event OLEDB QueryInterface Event OLEDB DataRead Event Occurs when DBCC commands are issued. Occurs when audit trace modifications are made. Occurs when a CREATE, ALTER, and DROP object commands are issued. Occurs when OLE DB provider calls are made for distributed queries and remote stored procedures. Occurs when OLE DB QueryInterface calls are made for distributed queries and remote stored procedures. Occurs when a data request call is made to the OLE DB provider. Occurs when an SQL statement executes. Include this event to identify Showplan operators. Each event is stored in a well-formed XML document. Note that the Binary column for this event contains the encoded Showplan. Use SQL Server Profiler to open the trace and view the Showplan. Occurs when a full text query executes. Reports the progress of a Service Broker conversation. Occurs when you use a feature that will be removed from a future version of SQL Server.

114 115 116 117 118

119

120 121

122

Showplan XML

123 124 125

SQL:FullTextQuery Broker:Conversation Deprecation Announcement

126

Deprecation Final Support

Occurs when you use a feature that will be removed from the next major release of SQL Server. Occurs when communication buffers in a parallel query plan have been temporarily written to the tempdb database. Occurs when a database is created, altered, or dropped. Occurs when a CREATE, ALTER, or DROP statement executes on database objects, such as schemas. Occurs when principals, such as users, are created, altered, or dropped from a database. Occurs when server objects are created, altered, or dropped. Occurs when there is an impersonation within server scope, such as EXECUTE AS LOGIN. Occurs when an impersonation occurs within the database scope, such as EXECUTE AS USER or SETUSER. Occurs when the owner is changed for objects in server scope.

127

Exchange Spill Event Audit Database Management Event Audit Database Object Management Event Audit Database Principal Management Event Audit Schema Object Management Event Audit Server Principal Impersonation Event Audit Database Principal Impersonation Event Audit Server Object Take Ownership Event

128

129

130

131

132

133

134

135

Audit Database Object Take Occurs when a change of owner for objects within database scope occurs. Ownership Event Broker:Conversation Group Occurs when Service Broker creates a new conversation group or drops an existing conversation group. Occurs when a process has been blocked for more than a specified amount of time. Does not include system processes or processes that are waiting on non deadlock-detectable resources. Use sp_configure to configure the threshold and frequency at which reports are generated. Reports the status of a transport connection managed by Service Broker.

136

137

Blocked Process Report

138 139

Broker:Connection

Broker:Forwarded Message Occurs when Service Broker forwards a message. Sent Broker:Forwarded Message Occurs when Service Broker drops a message that was intended to be Dropped forwarded. Broker:Message Classify Broker:Transmission Occurs when Service Broker determines the routing for a message. Indicates that errors have occurred in the Service Broker transport layer. The error number and state values indicate the source of the error. Indicates a poison message was detected because there were five consecutive transaction rollbacks on a Service Broker queue. The event contains the database ID and queue ID of the queue that contains the poison message.

140 141 142

143

Broker:Queue Disabled

144-145 Reserved

146

Showplan XML Statistics Profile

Occurs when an SQL statement executes. Identifies the Showplan operators and displays complete, compile-time data. Note that the Binary column for this event contains the encoded Showplan. Use SQL Server Profiler to open the trace and view the Showplan. Occurs when an attempt to acquire a lock is canceled because the attempt was part of a deadlock and was chosen as the deadlock victim. Provides an XML description of a deadlock. Occurs when Service Broker sends or receives a message acknowledgement. Occurs when a trace file closes during rollback.

148

Deadlock Graph

149 150 151 152

Broker:Remote Message Acknowledgement Trace File Close Reserved Audit Change Database Owner Audit Schema Object Take Ownership Event Reserved FT:Crawl Started

Occurs when ALTER AUTHORIZATION is used to change the owner of a database and permissions are checked to do that. Occurs when ALTER AUTHORIZATION is used to assign an owner to an object and permissions are checked to do that.

153 154 155

Occurs when a full-text crawl (population) starts. Use to check if a crawl request is picked up by worker tasks. Occurs when a full-text crawl (population) stops. Stops occur when a crawl completes successfully or when a fatal error occurs. Occurs when an exception is encountered during a full-text crawl. Usually causes the full-text crawl to stop. Reports audit messages related to Service Broker dialog security. Reports audit messages related to Service Broker transport security. Occurs when Service Broker is unable to retain a received message that should have been delivered to a service.

156

FT:Crawl Stopped

157 158 159 160 161 162

FT:Crawl Aborted Audit Broker Conversation Audit Broker Login Broker:Message Undeliverable

Broker:Corrupted Message Occurs when Service Broker receives a corrupted message. User Error Message Displays error messages that users see in the case of an error or exception. Occurs when a queue monitor starts an activation stored procedure, sends a QUEUE_ACTIVATION notification, or when an activation stored procedure started by a queue monitor exits. Occurs when a database object is altered. Occurs when a compiled query plan has been cached for the first time, recompiled, or removed from the plan cache. Occurs when a statement-level recompilation occurs. Occurs when the state of a mirrored database changes.

163

Broker:Activation

164 165 166 167

Object:Altered Performance statistics SQL:StmtRecompile Database Mirroring State Change

168

Showplan XML For Query Compile Showplan All For Query Compile Audit Server Scope GDR Event Audit Server Object GDR Event

Occurs when an SQL statement compiles. Displays the complete, compile-time data. Note that the Binary column for this event contains the encoded Showplan. Use SQL Server Profiler to open the trace and view the Showplan. Occurs when an SQL statement compiles. Displays complete, compile-time data. Use to identify Showplan operators. Indicates that a grant, deny, or revoke event for permissions in server scope occurred, such as creating a login. Indicates that a grant, deny, or revoke event for a schema object, such as a table or function, occurred.

169

170

171

172

Audit Database Object GDR Indicates that a grant, deny, or revoke event for database objects, such as Event assemblies and schemas, occurred. Audit Server Operation Event Audit Server Alter Trace Event Audit Server Object Management Event Audit Server Principal Management Event Audit Database Operation Event Audit Database Object Access Event TM: Begin Tran starting Occurs when Security Audit operations such as altering settings, resources, external access, or authorization are used. Occurs when a statement checks for the ALTER TRACE permission.

173

175

176

Occurs when server objects are created, altered, or dropped.

177

Occurs when server principals are created, altered, or dropped. Occurs when database operations occur, such as checkpoint or subscribe query notification. Occurs when database objects, such as schemas, are accessed. Occurs when a BEGIN TRANSACTION request starts.

178

180 181 182 183 184 185 186 187 188 189 190

TM: Begin Tran completed Occurs when a BEGIN TRANSACTION request completes. TM: Promote Tran starting Occurs when a PROMOTE TRANSACTION request starts. TM: Promote Tran completed TM: Commit Tran starting TM: Commit Tran completed TM: Rollback Tran starting TM: Rollback Tran completed Occurs when a PROMOTE TRANSACTION request completes. Occurs when a COMMIT TRANSACTION request starts. Occurs when a COMMIT TRANSACTION request completes. Occurs when a ROLLBACK TRANSACTION request starts. Occurs when a ROLLBACK TRANSACTION request completes.

Lock:Timeout (timeout > 0) Occurs when a request for a lock on a resource, such as a page, times out. Progress Report: Online Index Operation Reports the progress of an online index build operation while the build process is running.

191 192 193 194 195 196 197 198

TM: Save Tran starting TM: Save Tran completed Background Job Error OLEDB Provider Information Mount Tape Assembly Load Reserved XQuery Static Type

Occurs when a SAVE TRANSACTION request starts. Occurs when a SAVE TRANSACTION request completes. Occurs when a background job terminates abnormally. Occurs when a distributed query runs and collects information corresponding to the provider connection. Occurs when a tape mount request is received. Occurs when a request to load a CLR assembly occurs.

Occurs when an XQuery expression is executed. This event class provides the static type of the XQuery expression. Occurs when a query registration cannot be subscribed. The TextData column contains information about the event. Information about active subscriptions is stored in internal parameter tables. This event class occurs when a parameter table is created or deleted. Typically, these tables are created or deleted when the database is restarted. The TextData column contains information about the event. A query template represents a class of subscription queries. Typically, queries in the same class are identical except for their parameter values. This event class occurs when a new subscription request falls into an already existing class of (Match), a new class (Create), or a Drop class, which indicates cleanup of templates for query classes without active subscriptions. The TextData column contains information about the event. Tracks internal activities of query notifications. The TextData column contains information about the event.

199

QN: subscription

200

QN: parameter table

201

QN: template

202

QN: dynamics

[ @columnid = ] column_id Is the ID of the column to be added for the event. column_id is int, with no default. The following table lists the columns that can be added for an event. Column Column name number 1 TextData 2 BinaryData Description Text value dependent on the event class that is captured in the trace. Binary value dependent on the event class captured in the trace. ID of the database specified by the USE database statement, or the default database if no USE database statement is issued for a given connection. The value for a database can be determined by using the DB_ID function. 4 5 TransactionID LineNumber System-assigned ID of the transaction. Contains the number of the line that contains the error. For events that involve Transact-SQL statements, like SP:StmtStarting, the LineNumber contains the line

DatabaseID

number of the statement in the stored procedure or batch. 6 7 8 9 NTUserName NTDomainName HostName ClientProcessID Microsoft Windows user name. Windows domain to which the user belongs. Name of the client computer that originated the request. ID assigned by the client computer to the process in which the client application is running. Name of the client application that created the connection to an instance of SQL Server. This column is populated with the values passed by the application rather than the displayed name of the program. SQL Server login name of the client. Server Process ID assigned by SQL Server to the process associated with the client. Amount of elapsed time (in microseconds) taken by the event. This data column is not populated by the Hash Warning event. Time at which the event started, when available. Time at which the event ended. This column is not populated for starting event classes, such as SQL:BatchStarting or SP:Starting. It is also not populated by the Hash Warning event. Number of logical disk reads performed by the server on behalf of the event. This column is not populated by the Lock:Released event. Number of physical disk writes performed by the server on behalf of the event. Amount of CPU time (in milliseconds) used by the event. Represents the bitmap of permissions; used by Security Auditing. Severity level of an exception. Type of event subclass. This data column is not populated for all event classes. System-assigned ID of the object. Success of the permissions usage attempt; used for auditing. 23 Success 1 = success0 = failure 24 25 26 27 IndexID IntegerData ServerName EventClass ID for the index on the object affected by the event. To determine the index ID for an object, use the indid column of the sysindexes system table. Integer value dependent on the event class captured in the trace. Name of the instance of SQL Server, either servername or servername\instancename, being traced. Type of event class being recorded.

10

ApplicationName

11 12 13 14

LoginName SPID Duration StartTime

15

EndTime

16 17 18 19 20 21 22

Reads Writes CPU Permissions Severity EventSubClass ObjectID

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

ObjectType NestLevel State Error Mode Handle ObjectName DatabaseName FileName OwnerName RoleName TargetUserName DBUserName LoginSid

Type of object, such as: table, function, or stored procedure. The nesting level at which this stored procedure is executing. See @@NESTLEVEL (Transact-SQL). Server state, in case of an error. Error number. Lock mode of the lock acquired. This column is not populated by the Lock:Released event. Handle of the object referenced in the event. Name of object accessed. Name of the database specified in the USE database statement. Logical name of the file name modified. Owner name of the referenced object. Name of the database or server-wide role targeted by a statement. User name of the target of some action. SQL Server database user name of the client. Security identifier (SID) of the logged-in user.

TargetLoginName Login name of the target of some action. TargetLoginSid SID of the login that is the target of some action.

ColumnPermissions Column-level permissions status; used by Security Auditing. LinkedServerName Name of the linked server. ProviderName MethodName RowCounts RequestID XactSequence EventSequence BigintData1 BigintData2 GUID IntegerData2 Name of the OLE DB provider. Name of the OLE DB method. Number of rows in the batch. ID of the request containing the statement. A token to describe the current transaction. Sequence number for this event. bigint value, which is dependent on the event class captured in the trace. bigint value, which is dependent on the event class captured in the trace. GUID value, which is dependent on the event class captured in the trace. Integer value, which is dependent on the event class captured in the trace.

56 57 58 59

ObjectID2 Type OwnerID ParentName

ID of the related object or entity, if available. Integer value, which is dependent on the event class captured in the trace. Type of the object that owns the lock. For lock events only. Name of the schema the object is within. Indicates whether the event occurred on a system process or a user process.

60

IsSystem

1 = system 0 = user.

61 62

Offset

Starting offset of the statement within the stored procedure or batch.

SourceDatabaseID ID of the database in which the source of the object exists. 64-bit hash based on the text of an ad hoc query or the database and object ID of an SQL object. This value can be passed to sys.dm_exec_sql_text() to retrieve the associated SQL text.

63

SqlHandle

64

The login name of the user who originated the session. For example, if you connect to SQL Server using Login1 and execute a statement as Login2, SessionLoginName SessionLoginName displays Login1, while LoginName displays Login2. This data column displays both SQL Server and Windows logins.

[ @on = ] on Specifies whether to turn the event ON (1) or OFF (0). on is bit, with no default. If on is set to 1, and column_id is NULL, then the event is set to ON and all columns are cleared. If column_id is not null, then the column is set to ON for that event. If on is set to 0, and column_id is NULL, then the event is turned OFF and all columns are cleared. If column_id is not null, then the column is turned OFF. This table illustrates the interaction between @on and @columnid. @on ON (1) @columnid Event is turned ON. NULL All Columns are cleared. NOT NULL Column is turned ON for the specified Event. Event is turned OFF. OFF (0) NULL All Columns are cleared. NOT NULL Column is turned OFF for the specified Event. Result

Return Code Values The following table describes the code values that users may get following completion of the stored procedure. Return Description

code 0 1 2 3 4 9 11 13 16 No error. Unknown error. The trace is currently running. Changing the trace at this time will result in an error. The specified event is not valid. The event may not exist or it is not an appropriate one for the store procedure. The specified column is not valid. The specified trace handle is not valid. The specified column is used internally and cannot be removed. Out of memory. Returned when there is not enough memory to perform the specified action. The function is not valid for this trace.

Remarks sp_trace_setevent performs many of the actions previously executed by extended stored procedures available in earlier versions of SQL Server. Use sp_trace_setevent instead of the following:

xp_trace_addnewqueue xp_trace_eventclassrequired xp_trace_seteventclassrequired

Users must execute sp_trace_setevent for each column added for each event. During each execution, if @on is set to 1, sp_trace_setevent adds the specified event to the list of events of the trace. If @on is set to 0, sp_trace_setevent removes the specified event from the list. Parameters of all SQL Trace stored procedures (sp_trace_xx) are strictly typed. If these parameters are not called with the correct input parameter data types, as specified in the argument description, the stored procedure will return an error. For an example of using trace stored procedures, see How to: Create a Trace (Transact-SQL). Permissions User must have ALTER TRACE permission.

You might also like