Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Created November 18, 2025 19:33
Show Gist options
  • Select an option

  • Save MarkPryceMaherMSFT/203b67eaf41c9244fb2bff3e8cde68ae to your computer and use it in GitHub Desktop.

Select an option

Save MarkPryceMaherMSFT/203b67eaf41c9244fb2bff3e8cde68ae to your computer and use it in GitHub Desktop.
Clean up evented events
-- Stop the Extended Events session if it is running
IF EXISTS (
SELECT 1
FROM sys.server_event_sessions
WHERE name = 'MonitorTableQueries'
)
BEGIN
ALTER EVENT SESSION [MonitorTableQueries] ON SERVER STATE = STOP;
PRINT 'MonitorTableQueries session stopped.';
END
ELSE
BEGIN
PRINT 'MonitorTableQueries session does not exist or is already stopped.';
END
GO
-- Drop the Extended Events session
IF EXISTS (
SELECT 1
FROM sys.server_event_sessions
WHERE name = 'MonitorTableQueries'
)
BEGIN
DROP EVENT SESSION [MonitorTableQueries] ON SERVER;
PRINT 'MonitorTableQueries session dropped successfully.';
END
ELSE
BEGIN
PRINT 'MonitorTableQueries session does not exist.';
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment