删除记录时的外键参考错误,大家帮帮我吧!DELETE 语句与 COLUMN REFERENCE 约束
建库语句:
create database SFTMG
use SFTMG
create table t_project(pid smallint IDENTITY,pname varchar(80),pnumber varchar(10),prequir varchar(3000),pdescribe varchar(4000),pisend smallint,primary key (pid),unique(pnumber))
create table t_active(aid smallint IDENTITY,aname varchar(80),anumber varchar(10),adescribe varchar(4000),astarttime datetime,aendtime datetime,pid smallint,precostdate mallint,primary key(aid),foreign key (pid) references t_project(pid))
create table t_manpower(mid smallint IDENTITY,mname varchar(40),msex smallint,mbirthday datetime,mknowlege varchar(20),mcost smallint,misend smallint,mresume varchar(4000),primary key(mid))
create table t_A_M(aid smallint,mid smallint, primary key (aid,mid),foreign key(aid) references t_active(aid),foreign key(mid) references t_manpower(mid))
create table t_A_A(aid smallint,Paid smallint, primary key (aid,Paid),foreign key(aid) references t_active(aid),foreign key(paid) references t_active(aid))
这种结构的数据,在进行删除时出现错误:
执行语句:
begin tran
declare @aid integer
set @aid=5
delete from t_A_m where aid=@aid
delete from t_A_A where aid=@aid
delete from t_active where pid=2 and aid=@aid
commit tran
错误信息:
(所影响的行数为 0 行)
(所影响的行数为 0 行)
服务器: 消息 547,级别 16,状态 1,行 6
DELETE 语句与 COLUMN REFERENCE 约束 'FK_t_A_A_t_active1' 冲突。该冲突发生于数据库 'SFTMG',表 't_A_A', column 'paid'。
语句已终止。
为什么出错了,我不是提前删除关联表的了吗?