全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:801
推到 Plurk!
推到 Facebook!

trigger中可否抓取其中幾個特定欄位insert into到一新table?

尚未結案
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-11 18:28:45 IP:202.145.xxx.xxx 未訂閱
以下紅色部份可以只insert into被select的record其中幾個欄位?而不是 整個record都insert into
CREATE trigger [test] on [oo]
for insert,delete,update
as
begin
declare @ins_count int,
@del_count int    if @@rowcount = 0 return

select @ins_count=count(*) from inserted 
select @del_count=count(*) from deleted    if @del_count>0 begin
insert into oodel select * from deleted    end
if @ins_count>0 begin
insert into ooins select * from inserted    end
end
堅持從洗馬桶做起 Eric
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-12 20:22:50 IP:218.32.xxx.xxx 未訂閱
引言: 以下紅色部份可以只insert into被select的record其中幾個欄位?而不是 整個record都insert into
CREATE trigger [test] on [oo]
for insert,delete,update
as
begin
declare @ins_count int,
@del_count int    if @@rowcount = 0 return

select @ins_count=count(*) from inserted 
select @del_count=count(*) from deleted
-- 只是取得 inserted 與 deleted 兩個 "暫存檔", 以方便判斷 增刪修.    if @del_count>0 begin
insert into oodel select * from deleted
-- insert into oodel(f1,f2...) selecct f1,f2... from deleted
end
if @ins_count>0 begin
insert into ooins select * from inserted    end
end
堅持從洗馬桶做起 Eric
系統時間:2024-07-01 10:42:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!