How to Create an Extended Event in SQL Server - SQL Server DBA Tutorial

In this video you will learn how to create an Extended Event in SQL Server using SQL Server Management studio as well as using T-SQL Script. It also shows step by step process of creating a New Session, choosing events that you would like to capture, filtering the events data (fields) and saving the output to a disk location. It also demonstrates how to get list of Extended Events in SQL Server, how to watch Live Data of a session, how to analyze captured data and how to start and stop a session in extended events in SQL Server.

Script used in the video to Create Extended Event in SQL Server

CREATE EVENT SESSION [DatabaseEvent] ON SERVER 
ADD EVENT sqlserver.database_attached(
    ACTION(sqlserver.database_name,sqlserver.nt_username,sqlserver.username)),
ADD EVENT sqlserver.database_created(
    ACTION(sqlserver.database_name,sqlserver.nt_username,sqlserver.username)),
ADD EVENT sqlserver.database_detached(
    ACTION(sqlserver.database_name,sqlserver.nt_username,sqlserver.username)),
ADD EVENT sqlserver.database_started(
    ACTION(sqlserver.database_name,sqlserver.nt_username,sqlserver.username)) 
ADD TARGET package0.event_file(SET filename=N'C:\SQLSysBackup\DatabaseEvents.xel')
WITH (STARTUP_STATE=OFF)
GO


How to Create an Extended Event in SQL Server - SQL Server DBA Tutorial