Avery B
Avery B

Reputation: 237

Calling Stored Procedure on Table Update T-SQL

I am currently working creating a stored procedure in SQL Server 2014. Ideally, I would like to invoke some setting so that each time a certain table in my database updates, the stored procedure is run again (I'm not sure if it matters, but the stored procedure queries the table that it is looking for the update on). I have looked at documentation for both T-SQl and SQl Server, but I am unable to find any information confirming or denying whether or not this is feasible. Does anyone know if this is possible?

Upvotes: 1

Views: 1270

Answers (1)

womp
womp

Reputation: 116987

SQL Server has triggers that can be created on tables which will fire on operations done to the table. For example:

CREATE TRIGGER AfterUpdate
ON mydatabase.mytable
AFTER INSERT, UPDATE, DELETE 
AS
   EXEC myStoredProc
GO

You can read more about triggers in the documentation. Creating Triggers

Upvotes: 4

Related Questions