線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1116
推到 Plurk!
推到 Facebook!

更改受外键约束的主键的值

尚未結案
danielldf
一般會員


發表:44
回覆:60
積分:20
註冊:2003-05-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-31 10:35:39 IP:219.130.xxx.xxx 未訂閱
参考论坛前辈的意见,我设计如下数据库: create table mas (M varchar(4) primary key not null) go create table detail (s int identity(1,1) not null, D varchar(4) constraint Mfk references mas(M) not null) go create trigger TR_change on mas for update as declare @ins_mater_no varchar(4), @del_mater_no varchar(4) begin if @@rowcount = 0 return if update(m) begin declare cur_ins scroll cursor for select m from inserted declare cur_del scroll cursor for select m from deleted open cur_ins open cur_del fetch cur_ins into @ins_mater_no fetch cur_del into @del_mater_no while (@@fetch_status=0) begin update detail set d=@ins_mater_no where d=@del_mater_no fetch cur_ins into @ins_mater_no fetch cur_del into @del_mater_no end close cur_ins close cur_del deallocate cur_ins deallocate cur_del end end go insert into mas values('abcd') update mas set m='a01' where m='abcd' 到最后一步始终是无法实现更改主表的值,请各位先进指教!(数据库是MS SQL2000) 努力过,还有什么遗憾呢!
系統時間:2024-06-29 17:55:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!