请教一下关于创建课程表时关于先行课程的有关问题

请问一下关于创建课程表时关于先行课程的问题
创建课程表的语句:
create table Course(
Cno char(4), primary key,Cname char(20) not null,Cpno char(4),
foreign key (Cpno) references Course(Cno)
);

想请问一下大神,如果要保证先行课程不矛盾(即出现互为先行课程,或者先行课程出现死循环的情况),要怎么写呢???就是我想保证更新表若把两个课程更新成互为先行课程时它会报错,怎么办?
------解决思路----------------------
引用:
诶我百度了一下好像就是这个。。但是表的结构好像不太一样。。。我是初学的,用的sqlplus,大神能不能写段代码来参考参考?



declare @oldid int 
declare @newid int 
set @oldid = 6 
set @newid = 4
-- 將ID为6的课程更新成ID为4 
;with tbl01(id, pid, name) as 
(
select 1, 0, 'A' union all
select 2, 1, 'AB' union all
select 3, 0, 'C' union all
select 4, 3, 'CD' union all
select 5, 4, 'CDE' union all
select 6, 5, 'CDEF' 
),
cte as
(
select 0 as lvl, id, pid, name from tbl01 where id=@oldid -- 指定需要更新的ID
union all
select lvl+1, t2.id, t2.pid, t2.name from cte t1 
inner join tbl01 t2 
on t1.pid=t2.id 
)
--select id, pid, name from cte order by lvl
update tbl01 set id = @newid -- 更新的新ID
where id = @oldid 
and @newid not in(select pid from cte)  -- 如果新ID属于旧ID的父节点(先行课程),则不更新

看看是不是这样了?