sql server - How to check if running store procedure was triggered by job? -
is there way check within store procedure whether triggered job or using other methods i.e. ssis, @ hoc query etc? there similar question sql server find jobs running procedure check job steps, not need. this scenario. i have sp spdosomethingimportant , can run job or i.e. user in database. so within sp want have check if trigger job , name or id of job. i created following sproc: create procedure testme insert test_log select * sys.dm_exec_sessions session_id = @@spid go i ran ssms. in test_log , column program_name "microsoft sql server management studio - query" i created job run sproc. in test_log , column program_name "sqlagent - tsql jobstep (job 0xcb393e8ff0e9d44485204d0100803469 : step 1)" so if didn't want pass parameter indicate if it's running job, think figure out sys.dm_exec_sessions.program_name