更改受外键约束的主键的值 |
尚未結案
|
danielldf
一般會員 發表:44 回覆:60 積分:20 註冊:2003-05-12 發送簡訊給我 |
参考论坛前辈的意见,我设计如下数据库:
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) 努力过,还有什么遗憾呢!
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |