Partilhar via


Defining Event Chronicle Rules

Event chronicle rules maintain the data in event chronicle tables. Each event chronicle has a name, an action, and an action time-out.

Rule Name

The event chronicle rule name uniquely identifies the rule in the Notification Services application. The rule name is used to name database objects. For consistency, the event chronicle name should match the name of the event chronicle table.

Action

The action contains the code that maintains data in the chronicle tables, keeping the data in a usable state for your application. For example, each time a new event batch is processed, the statements in the action can delete all existing data in an event chronicle table and then insert the fresh event data.

The statements in the action can be one or more Transact-SQL queries or can be a Transact-SQL EXECUTE statement that runs a stored procedure.

The action statements run each time the generator processes an event batch. They complete before the generator runs subscription rules, which generate notification. Therefore, the event chronicle is updated before it is used to generate notifications.

Note

If you want to maintain the chronicle data after notifications are generated, add Transact-SQL queries or stored procedure calls to subscription event rules. For more information, see Defining Event Rules.

The action's Transact-SQL statements typically select data from an event class and insert or update data in the event chronicle. The following example shows sample Transact-SQL statements for an action. The statements select new data from the StockEvents event class and insert the data into StockEventChron chronicle. Then, they update stock prices for stocks that are already in the chronicle.

-- Insert New Stock Symbols with Prices
INSERT dbo.StockEventsChron (StockSymbol, StockPrice)
SELECT e.StockSymbol, e.StockPrice
    FROM dbo.StockEvents AS e
    WHERE e.StockSymbol
        NOT IN (SELECT StockSymbol FROM dbo.StockEventsChron);
-- Update Existing Stock Symbols with New Prices
UPDATE dbo.StockEventsChron
    SET StockPrice = e.StockPrice
    FROM dbo.StockEvents AS e 
    JOIN dbo.StockEventsChron AS c
        ON e.StockSymbol = c.StockSymbol
        WHERE e.StockPrice > c.StockPrice;

Note

If you are defining an application in an XML file, you must replace reserved XML characters, such as '>', with their entity references. For more information, see XML Reserved Characters.

All statements in an action are part of the same transaction. They either all complete or are all rolled back.

For more information about creating Transact-SQL queries, see Query Fundamentals.

Action Time-out

The action time-out specifies the permitted length of time for statements in the action to complete. If the statements do not complete before the time-out occurs, Notification System rolls back the transaction, marks the event chronicle rule as failed, and writes an error to the event log.

Note

If an event chronicle rule fails, meaning there was an error or that a time-out occurred when maintaining the event chronicle, related subscription event rules that would fire within the same generator quantum will also fail. Scheduled rules will not fail because they use the most current data.

To define an event chronicle rule
Event Chronicle Rule Examples

The following topics provide examples of event chronicle rules.

See Also

Reference

EventChronicle
EventChronicleRule
EventFieldCollection

Concepts

Defining Core Event Class Properties
Defining Indexes for an Event Class
Defining Event Rules

Other Resources

Defining Event Classes
EventClass Element (ADF)
Defining Notification Services Applications
CREATE TABLE (Transact-SQL)
INSERT (Transact-SQL)
SELECT (Transact-SQL)
UPDATE (Transact-SQL)
DELETE (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance