sp_trace_generateevent (Transact-SQL)
建立使用者定義事件。
[!附註]
這個預存程序未被取代。 所有其他與追蹤相關的預存程序都已被取代。
語法
sp_trace_generateevent [ @eventid = ] event_id
[ , [ @userinfo = ] 'user_info' ]
[ , [ @userdata = ] user_data ]
引數
[ @eventid=] event_id
這是要開啟的事件識別碼。 event_id 是 int,沒有預設值。 這個識別碼必須是從 82 到 91 的事件編號,如 sp_trace_setevent 所設定,它代表使用者自訂的事件。[ @userinfo= ] 'user_info'
這是用來識別事件原因的選擇性使用者定義字串。 user_info 是 nvarchar(128),預設值是 NULL。[ @userdata= ] user_data
這是選擇性的使用者指定事件資料。 user_data 是 varbinary(8000),預設值是 NULL。
傳回碼值
下表描述在預存程序完成之後,使用者可能得到的代碼值。
傳回碼 |
說明 |
---|---|
0 |
沒有錯誤。 |
1 |
未知的錯誤。 |
3 |
指定的事件無效。 事件可能不存在,也可能是不適合預存程序。 |
13 |
記憶體用完。 當沒有足夠的記憶體可以執行指定的動作時,便傳回這個代碼。 |
備註
sp_trace_generateevent 是一個 Microsoft SQL Server 2000 預存程序,它會執行先前舊版 SQL Server 提供的 xp_trace_* 擴充預存程序所執行的許多動作。 請利用 sp_trace_generateevent 來取代 xp_trace_generate_event。
您只能搭配 sp_trace_generateevent 使用使用者定義事件的識別碼。 如果使用其他事件識別碼,SQL Server 會發生錯誤。
所有 SQL 追蹤預存程序 (sp_trace_xx) 的參數都具備嚴格的類型。 如果沒有依照引數描述所指定,以正確的輸入參數資料類型來呼叫這些參數,預存程序會傳回錯誤。
權限
使用者必須有 ALTER TRACE 權限。
範例
下面範例會在範例資料表中建立使用者可設定事件。
--Create a sample table.
CREATE TABLE user_config_test(col1 int, col2 char(10));
--DROP the trigger if it already exists.
IF EXISTS
(SELECT * FROM sysobjects WHERE name = 'userconfig_trg')
DROP TRIGGER userconfig_trg;
--Create an ON INSERT trigger on the sample table.
CREATE TRIGGER userconfig_trg
ON user_config_test FOR INSERT;
AS
EXEC master..sp_trace_generateevent
@event_class = 82, @userinfo = N'Inserted row into user_config_test';
--When an insert action happens, the user-configurable event fires. If
you were capturing the event id=82, you will see it in the Profiler output.
INSERT INTO user_config_test VALUES(1, 'abc');
請參閱
參考
sys.fn_trace_geteventinfo (Transact-SQL)
sp_trace_setevent (Transact-SQL)