資料庫觸發器

2021-05-23 02:37:55 字數 1036 閱讀 4919

最近做了個觸發器的例子

create trigger tru_user

on  _user for update

asif update(status)

begin

update _user set stopflag=1 from inserted where _user.userid=inserted.userid and inserted.status='a'

update _user set stopflag=0 from inserted where _user.userid=inserted.userid and inserted.status='s'

update _user set stopflag=2 from inserted where _user.userid=inserted.userid and inserted.status='d'

endgo

create trigger tru_pat_dict_patrol_place

on  pat_dict_patrol_place for update

asbegin

update pat_dict_patrol_place set updatetime=getdate() from inserted where pat_dict_patrol_place.patplaceid=inserted.patplaceid

endgo

create trigger tru_pat_dict_patrolplace_facility_relation

on  pat_dict_patrolplace_facility_relation for update

asbegin

update pat_dict_patrolplace_facility_relation set updatetime=getdate() from inserted where pat_dict_patrolplace_facility_relation.patplaceid=inserted.patplaceid

endgo

資料庫觸發器

觸發器是一種特殊型別的儲存過程,它不同於我們前面介紹過的儲存過程。觸發器主要是通過事件進行觸發而被執行的,而儲存過程可以通過儲存過程名字而 被直接呼叫。當對某一表進行諸如update insert delete 這些操作時,sql server 就會自動執行觸發器所定義的sql 語句,從而確保對資料...

資料庫 觸發器

觸發器的概念 是使用者定義在關係表上的一類有事件驅動的特殊過程。一旦定義,任何對錶的增刪改操作均有伺服器自動啟用相應的觸發器,在dbms核心層進行集中的完整性控制。類似於約束,但比約束更靈活。觸發器的分類 dml觸發器 dml data manipulation language 觸發器是當資料庫伺...

資料庫觸發器

想要某條語句在事件發生時自動執行 某錶發生改動時,自動處理 除下列三個關鍵字意外的不支援觸發器 建立觸發器時,需要給出四條資訊 create trigger newproduct after insert on products foreach rowselect product added 分析 ...