Where does a Server trigger save in SQL Server?

2019-01-26 12:40发布

A couple of days ago , I was practicing and I wrote some triggers like these :

create trigger trg_preventionDrop
on all server 
for drop_database
as
print 'Can not Drop Database'
rollback tran

go 

create trigger trg_preventDeleteTable
on database
for drop_table
as 
print 'you can not delete any table'
rollback tran

But the problem is I don't know where it has saved and How can I delete or edit those.

Thank you

2条回答
We Are One
2楼-- · 2019-01-26 13:35

Server Trigger

You can see them here

select * from sys.server_triggers

To drop use this syntax

drop trigger trg_preventionDrop on all server 

In Management Studio they are under the "Server Objects" -> "Triggers" node

Database Trigger

You can see them here

select * from yourdb.sys.triggers

To drop use this syntax

drop trigger trg_preventDeleteTable on database

In Management Studio they are under the "Databases" -> "yourdb" -> "Programmability" -> "Database Triggers" node

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-26 13:39

trigger on a particular table resides in "DataBase" -> "YourDb" -> "YourTable" -> "Trigger" folder in Management Studio

also one can find the trigger on a particular table by execution the following sql:
EXEC sp_helptrigger yourtablename

查看更多
登录 后发表回答