lwmc.net
當前位置:首頁 >> Sql SErvEr觸發器 怎樣將一個表中的某一條數據刪除... >>

Sql SErvEr觸發器 怎樣將一個表中的某一條數據刪除...

--創建測試表create table t_a(id int,name varchar(10));create table t_b(id int,name varchar(10));--測試數據insert into t_a(id,name) values (1,'a');--創建 for delete 觸發器create trigger trg_t_a_1 on t_afor deleteasbegininsert in...

CREATE TRIGGER 觸發器名字 ON 你的那種主表 FOR DELETE AS BEGIN DELETE FROM 你的那張子表 WHERE 子表的關聯主表ID IN ( SELECT 主表ID FROM deleted ); END; go

create trigger insert_table --創建觸發器,觸發器名稱 insert_table on tablea --哪個表的觸發器for insert --哪個動作觸發as declare @a varchar(100) --定義一個參數 select @a=id from inserted --取插入數據中的id update tableb set n=n+...

--創建測試表 create table t_a(id int,name varchar(10)); create table t_b(id int,name varchar(10)); --測試數據 insert into t_a(id,name) values (1,'a'); --創建 for delete 觸發器 create trigger trg_t_a_1 on t_a for delete as begin...

如下: CREATE TRIGGER del_kh ON dbo.卡信息表 AFTER DELETE AS insert into 作廢卡信息表(kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq) select kh,xm,xb,kmc,sjhm,sysycs,fxrq,dqrq from deleted ==== 觸發器激活時,會把刪除的記錄放在deleted臨時表...

SQL Server寫法: create trigger del_T on T insert of delete as if exists(select 1 from deleted) begin raiserror 50001 N'不可刪除' return end go 或用 create trigger del_T on T for delete as if exists(select 1 from deleted) begin ...

給個建議【寫個函數判斷一下就可以了】: 1.你獲取數據是不是主要根據導入時間來判斷,如果是 在按照導入時間判斷是7號(包含)以前,還是以后 2.如果是 7號(包含)以前 就取導入時間 datepart(dd,getdate())

create trigger tr_ins_del_tbA on tbA instead of insert as begin if exists(select 1 from inserted where errorid=5) begin insert into tbB select * from inserted where errorid=5 end insert into tbA select * from inserted where err...

很簡單. reate or replace trigger tri_name after update on 表的名字 for each row begin if Userstate=0 then update 另外一個表 set UserState = '0'; dbms_output.put.line('已改變'); else null; end; 觸發器比較經典的用法,百度就一大堆.

-- 查看數據庫已有觸發器 use yourdatabase go select * from sysobjects where xtype='TR' -- 查看單個觸發器 exec sp_helptext '觸發器名' --刪除觸發器: 基本語句如下: drop trigger trigger_name

網站首頁 | 網站地圖
All rights reserved Powered by www.fpyfpq.tw
copyright ©right 2010-2021。
內容來自網絡,如有侵犯請聯系客服。[email protected]
加拿大快乐8开奖网站