concept event in category sql

appears as: events, event, n event, Event, events, The event, EVENT
SQL Server MVP Deep Dives Vol. 2

This is an excerpt from Manning's book SQL Server MVP Deep Dives Vol. 2.

Today when I look back on some of my personal growing pains, I recall graduating from boot camp, as well as the accomplishment I felt during the precise moment I was called a Marine for the first time. I also recall my discussion with one of the drill instructors as he reminded me that all the pain we pushed through and all the training we’d endured was designed for us to become better Marines. This training ensured we’d have a better chance of surviving events that could happen in the future.

StreamInsight is a complex event-processing engine from Microsoft that allows developers to write applications that can process potentially high-volume, low-latency streams of events within the business. StreamInsight is a .NET framework that allows you to write applications that can respond efficiently, in close to real time, to events occurring in your business. Businesses can obtain insight into the business events by being able to source, query, analyze, and react to potentially tens of thousands of events per second. They can then proactively drive decision making across the enterprise based on this insight. StreamInsight’s query language is Language Integrated Query, or LINQ.

SQL Server MVP Deep Dives

This is an excerpt from Manning's book SQL Server MVP Deep Dives.

Every table should have a primary key to make sure that you have some way to distinguish one row from other rows. In addition, it’s important to make sure that you have either the primary key or a unique key on a value in the table that has some meaning. An identity value in the table doesn’t have any actual meaning, as you could have two rows with exactly the same value other than the identity key, and the two rows would be technically indistinguishable from one another. This isn’t always completely possible, as there are some tables where a key that has full meaning can’t be created, such as a table that logs events that have occurred, where multiple events of the same type could occur at the same instance. For logging situations, adding a sequence number is an acceptable trade-off, though that shouldn’t be the only value in the key.

Listing 1. Using Extended Events to monitor long-running queries
USE master; GO -- Create Event Session CREATE EVENT SESSION GetLongRunningQueries ON SERVER ADD EVENT sqlserver.sql_statement_completed( ACTION (sqlserver.sql_text) WHERE sqlserver.database_id=1 AND duration > 20000); GO -- Add Event Bucketing target -- source_type = {0|1}, 0 = event 1 = action ALTER EVENT SESSION GetLongRunningQueries ON SERVER ADD TARGET package0.synchronous_bucketizer (set filtering_event_name='sqlserver.sql_statement_completed', source_type=1, source='sqlserver.sql_text'); GO -- Start the Event Session ALTER EVENT SESSION GetLongRunningQueries ON SERVER STATE=START; GO -- For testing purpose we will create a stored procedure that will run -- longer than 20 seconds CREATE PROCEDURE usp_WaitForATime AS BEGIN DECLARE @D DATETIME=GETDATE(),@S VARCHAR(128); WHILE (DATEDIFF(ss,@D,GETDATE())<22) SET @S = @@VERSION; END; GO -- Execute the procedure 5 times -- This works in SQL Server Management Studio EXEC usp_WaitForATime; GO 5 -- Getting the information DECLARE @MyXML XML; SELECT @MyXML = CAST(T.target_data AS XML) FROM sys.dm_xe_session_targets T JOIN sys.dm_xe_sessions S ON S.address = T.event_session_address JOIN sys.server_event_sessions ES ON S.name = ES.name WHERE T.target_name = 'synchronous_bucketizer' AND S.name = 'GetLongRunningQueries'; -- Display the information as raw XML SELECT @MyXML AS XML_Representation; -- Display the information using XQuery for a better output SELECT T.Slot.value('@count', 'int') [NbmOfExecutions], T.Slot.value('value[1]', 'varchar(MAX)') [QueryText] FROM @MyXML.nodes('/BucketizerTarget/Slot') AS T(Slot) -- Clean-Up DROP PROCEDURE usp_WaitForATime; GO ALTER EVENT SESSION GetLongRunningQueries ON SERVER STATE=STOP; GO DROP EVENT SESSION GetLongRunningQueries ON SERVER; GO

Events are specific points of interest in the code of an application. In the case of SQL Server, they can be the start of a broker activation task, a lock timeout, a cache hit, and so on.

When an event fires, it signals that the point of interest was reached. The firing of an event can be used for tracing purposes or triggering actions. The actions (or the consumption of the event) can be synchronous or asynchronous.