Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Generate Scripts For All Triggers in Database Using Microsoft SQL Server Management Studio

I'd like to generate an SQL Script that contains the SQL to create all of the triggers that exist in our database. The triggers were added directly via the SSMS query pane so, there is currently no source other than the trigger on the database itself.

I have already tried the method where you right-click the database, select Tasks->Generate Scripts and used the "Script Entire Database and All Objects" option. While this does create a SQL script for the tables and constraints, it does not generate SQL for the triggers.

I also understand that I can right click on each trigger in the database and select the Generate SQL Script option but, there is currently 46 tables under audit (For Insert, Update, and Delete).

Rather manually generate an insert, update, and delete trigger script for each of the 46 tables, is there an easier way to do this? Or, should I start clicking, copying, and pasting?

like image 561
Grasshopper Avatar asked Nov 02 '12 17:11

Grasshopper


People also ask

How do I create a script for all triggers in SQL Server?

Database-> Tasks-> Generate Scripts -> Next -> NextOn Choose Script Options UI, under Table/View Options Heading, set Script Triggers to True.

How do you generate create table script for all tables in SQL Server database?

Now right-click the database then Tasks->Generate scripts. After that a window will open. Select the database and always check "script all objects in the selected database". It will generate a script for all the tables, sp, views, functions and anything in that database.


1 Answers

Database-> Tasks-> Generate Scripts -> Next -> Next

On Choose Script Options UI, under Table/View Options Heading, set Script Triggers to True.

enter image description here

enter image description here

like image 146
Kapil Khandelwal Avatar answered Sep 28 '22 05:09

Kapil Khandelwal