sqlserver怎么使用TSQL语句禁用、启用、删除DML触发器,以books表为例,有触发器tr_books_insert和books_delete_trigger
时间: 2023-12-14 09:37:03 浏览: 162
sqlserver 禁用触发器和启用触发器的语句
要禁用一个DML触发器,可以使用DISABLE TRIGGER语句,其语法如下:
```sql
DISABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL }
ON { object_name | DATABASE | ALL SERVER }
[ ; ]
```
要启用一个之前被禁用的DML触发器,可以使用ENABLE TRIGGER语句,其语法如下:
```sql
ENABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL }
ON { object_name | DATABASE | ALL SERVER }
[ ; ]
```
要删除一个DML触发器,可以使用DROP TRIGGER语句,其语法如下:
```sql
DROP TRIGGER [ IF EXISTS ]
[ schema_name . ] trigger_name [ ,...n ]
[ ; ]
```
以books表为例,禁用tr_books_insert触发器的语句如下:
```sql
DISABLE TRIGGER dbo.tr_books_insert ON dbo.books;
```
启用tr_books_insert触发器的语句如下:
```sql
ENABLE TRIGGER dbo.tr_books_insert ON dbo.books;
```
删除tr_books_insert触发器的语句如下:
```sql
DROP TRIGGER dbo.tr_books_insert;
```
同样,要禁用、启用、删除books_delete_trigger触发器,只需要将上述语句中的tr_books_insert替换为books_delete_trigger即可。
阅读全文