Run a Script each time a table is modified


I need to find the way to run a batch script (made by me) each time a single table in my Microsoft SQL Server is modified.

Kind of every time a field is updated or a new registry is created...

Been looking for a while but couldn't find anything. I hope you can help me!


You might want to have a look at triggers

1 Like

If I understand you correctly, you need to look at DDL triggers.

I don't understand what you mean by "a new registry is created", but I think you mean a new table or perhaps view or some other object.

I will! By a new registry I mean a new row. Direct translated from Spanish sorry.

You will need to create insert triggers, or do all inserts through stored procedures, that execute your batch code for each table you want to trigger execution. Know this will slow down inserts. What are you trying to accomplish with your batch?

1 Like

I only need it for one table. It is not a very used table, maybe 4 or 5 inserts and 4 or 5 updates a day.

The batch script will get the first field of the row that has been updated or inserted and use it as a variable in the script.

How many rows are in the table?

Create a job to run this, add a step as OS command (cmdexec)

bcp schema.table out -T -S server -d database-c -o \\path\table.txt

replace schema.table, server, database, path with your values.

1 Like

The table has around 5.000 rows.
I will try your idea during this week and I'll let you know the result!