问题描述
我想生成一个 SQL 脚本,其中包含用于创建我们数据库中存在的所有触发器的 SQL.触发器是通过 SSMS 查询窗格直接添加的,因此,除了数据库本身的触发器之外,目前没有其他来源.
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.
我已经尝试过右键单击数据库,选择Tasks->Generate Scripts
并使用脚本整个数据库和所有对象"选项的方法.虽然这确实为表和约束创建了 SQL 脚本,但它不会为触发器生成 SQL.
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.
我也知道我可以右键单击数据库中的每个触发器并选择生成 SQL 脚本"选项,但是,目前有 46 个表正在审核中(用于插入、更新和删除).
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).
而不是为 46 个表中的每一个手动生成插入、更新和删除触发器脚本,有没有更简单的方法来做到这一点?或者,我应该开始点击、复制和粘贴吗?
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?
推荐答案
Database-> Tasks-> Generate Scripts -> Next -> Next
在 Choose Script Options UI 上,在 Table/View Options Heading 下,将 Script Triggers 设置为 True.
On Choose Script Options UI, under Table/View Options Heading, set Script Triggers to True.
这篇关于如何使用 Microsoft SQL Server Management Studio 为数据库中的所有触发器生成脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!