-2

Can a Trigger be written for a View, that if data is selected from that view to trigger off another transaction?

1
  • 2
    Yes, no, maybe so. But more details on what your goals are would be needed in order to understand how to help you.
    – J.D.
    Commented Jun 3 at 12:57

1 Answer 1

2

Probably not. According to documentation, the triggers can be fired by:

  • DML commands. (I. e. INSERT, UPDATE, DELETE)

  • DDL commands. ("These events primarily correspond to Transact-SQL CREATE, ALTER, and DROP statements, and certain system stored procedures that perform DDL-like operations.")

  • LOGON (When someone logs into the SQL Server.)

There might be some creative workarounds to achieve kinda similar thing (depending on what exactly are you trying to do):

  • Consider e.g. this recent answer, that tracks big SELECTs using extended events. (But does not fire another SQL transaction.)

  • Or perhaps, instead of view, you could give your consumers stored procedure (inside of which, you will have much more freedom to do as you please).

Not the answer you're looking for? Browse other questions tagged or ask your own question.