0

I need to create a trigger on SQL database DB1 that fires when one or more row has been inserted in table T1.

The problem is that the table where i need the trigger could be drop and re-created in a second time, so, if i write the trigger on table T1 this would be dropped too.

what's the way to do that?

7
  • 3
    Then you need to manually recreate the trigger too. Thats the way to do it Commented Sep 21, 2017 at 11:01
  • there's not a way to make the trigger at DB node? Commented Sep 21, 2017 at 11:02
  • Why is the table getting dropped? That is unusual Commented Sep 21, 2017 at 11:03
  • A trigger is part of a table. Drop the table and the trigger is gone. Commented Sep 21, 2017 at 11:04
  • Why not TRUNCATE instead of DROP? That will retain the table schema and trigger. Commented Sep 21, 2017 at 11:05

1 Answer 1

2

You could create a DDL trigger that would recreate your trigger on table T1.

Maybe have the DDL trigger fire on create table statement, check if your T1 has been created, and, if so, recreate the trigger.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.