You might have things going on in your SQL server. Things you want to know that they happen. Things you don't want to happen. How can you become aware of such things?
You can catch them with a trace. I like to think of this trace as my KMDFM trace, from the song title "Looking for strange". At this stage, I don't want to capture the actual event, I just to know if any such events are going on.
Acknowledgements
Thanks for providing feedback and suggestions for this article:
Ekrem Önsoy, suggested the addition of error_reported.
Much appreciated!
Below you find the XE session. Note that you can create it using T-SQL (as below) and then use the XE GUI in SSMS to modify the trace. And then script it out again. etc...
--Stop trace if started
IF EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'LookingForStrange')
ALTER EVENT SESSION LookingForStrange ON SERVER STATE = STOP
--Delete trace if exists
IF EXISTS (SELECT * FROM sys.server_event_sessions WHERE name = 'LookingForStrange')
DROP EVENT SESSION LookingForStrange ON SERVER
--Create trace
CREATE EVENT SESSION [LookingForStrange] ON SERVER
ADD EVENT sqlserver.attention(
WHERE (package0.greater_than_uint64(database_id,(4))
AND package0.equal_boolean(sqlserver.is_system,(0)))) ,
ADD EVENT sqlserver.auto_stats(
WHERE ([database_id]>(4) AND [sqlserver].[is_system]=(0) AND [object_id]>(10000000) AND [duration]>(10))),
ADD EVENT sqlserver.database_file_size_change,
ADD EVENT sqlserver.database_started,
ADD EVENT sqlserver.lock_deadlock,
ADD EVENT sqlserver.lock_escalation,
ADD EVENT sqlserver.lock_timeout_greater_than_0,
ADD EVENT sqlserver.long_io_detected,
ADD EVENT sqlserver.error_reported(
ACTION(sqlserver.client_app_name, sqlserver.client_hostname,
sqlserver.database_name, sqlserver.sql_text, sqlserver.username)
WHERE (package0.greater_than_int64(severity,(10))
AND NOT sqlserver.like_i_sql_unicode_string(sqlserver.client_app_name,N'Microsoft SQL Server Management Studio%')
AND package0.not_equal_int64(error_number,(596))
AND package0.not_equal_int64(error_number,(9104))
AND error_number<>(17830) AND error_number<>(10060))),
--Begin performance section
ADD EVENT qds.query_store_plan_forcing_failed,
ADD EVENT sqlserver.exchange_spill,
ADD EVENT sqlserver.execution_warning,
ADD EVENT sqlserver.hash_spill_details,
ADD EVENT sqlserver.hash_warning,
ADD EVENT sqlserver.optimizer_timeout,
ADD EVENT sqlserver.query_memory_grant_blocking,
ADD EVENT sqlserver.query_memory_grants,
ADD EVENT sqlserver.sort_warning,
ADD EVENT sqlserver.window_spool_ondisk_warning
--End performance section
ADD TARGET package0.event_counter
GO
/*
--Start trace
ALTER EVENT SESSION LookingForStrange ON SERVER STATE = START
*/