几天来回答不出的原帖:http://www.csdn.net/expert/topic/999/999991.xml?temp=.9947016
解决方案 »
- 求一条多表查询的SQL
- [DBNETLIB][ConnectionWrite (send()).]一般性网络错误。请检查网络文档。 Insert Statement:
- 求一SQL语句,马上给分
- 求一个通用的查询存储过程
- 用SQL 把16进制转为10进制的?
- 恩信ERP,谁能评价一下?
- 若使用ODBC连接,而不是OLEDB, 还需安装MDAC吗?
- 请问用开发版是免费的吗?
- 执行一个存储过程花了3秒的时间,这正常吗?
- 用VB如何连接SQL SERVER 2005?
- 如下的建表语句不可以建起来,原因以及原理我也知道,但具体我没有一个明确的解释,哪位帮忙给出一个清晰的解释,给我解释一下我的理解?
- 什么叫位、字节、字?请大家告诉我哦!
bottom_id integer primary key,
top_id integer not null,
sub_top_id integer not null,
foreign key (top_id) references topTable(top_id) ,
foreign key (sub_top_id) references subTopTable(sub_top_id) on delete cascade)top_id的级联删除没有必要保留,因为表一中删除记录自然删除表2中记录,而删除表2中记录自然要删除表3中记录。
=================================================================
假设有如下的记录:topTable
--------------------------------
100 , 1
200 , 2subTopTable
---------------------------------
100 , 100
101 , 100
102 , 200bottomTable
---------------------------------
900, 100 , 102
901, 200 , 102以上的记录,如果我在topTable表中删除记录100,如果在bottomTable表中去掉外关键字top_id,在bottomTable表中的记录900肯定删除不了,那么就会出现数据与实际不相符。有没有理解错,请指教!!!
topTable应该是第一层,subTopTable是第二层,bottomTable是第三层。
应该将bottomTable中的
“top_id integer not null,”和
“foreign key (top_id) references topTable(top_id) on delete cascade,”两句都去掉。
bottomTable因为与subTopTable表中的sub_top_id外键关联,所以通过这个关系可以取到sub_top_id表中的ref_top_id值,此值可以代替bottomTable原来的“top_id integer not null,”。
不知你明白否?
上面是在2000下的报错,很明显,是吗
将 FOREIGN KEY 约束 'FK__bottomTab__sub_t__7D78A4E7' 引入表 'bottomTable' 中将导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其它 FOREIGN KEY 约束。
”
create table bottomTable(
bottom_id integer primary key,
sub_top_id integer not null,
foreign key (sub_top_id) references subTopTable(sub_top_id) on delete cascade)