sql无限级
❶ sql递归或级联删除操作,无限极,无限量
设置外键,在数据库中启用级联删除和级联更新选项
❷ 问个无限极分类的SQL查询
select id from 表 where parentit=2 or parentid in (select id from 表 where parentit=2)
如果是无限级别的子集下去,就要用循环了
declare @t table(id int)
insert into @t values(2)
while exists (select id from 表 where parentid in (select id from @t) and id not in (select id from @t))
begin
insert into @t select id from 表 where parentid in (select id from @t) and id not in (select id from @t)
end
delete from @t where id=2
select id from @t
select id from @t
❸ sql 无限极分类 递归查询
select * from 表名 where pid>10
从你的示例数据无法看出完整的编码规则,以上提供的SQL语句可能不适合实际当中的其他情况,但一定能适合你的示例数据。希望采纳,谢谢!
❹ 什么是 无限极分类(php。数据库)
那是一种关联关系....sql 里可以叫"自连接" 假设:表 Category 有以下字段: Id(PK),Cate_Name(varchar),Cate_Parent_Id(int) 数据: Id(编号ID) Cate_Name(类别名称) Cate_Parent_Id(父级Id) 1 BaseCategory 0 2 News 1 3 Article 1 4 Story 3 说明: Id 为 1 的基类别(没有父级类别) News,Article 为 基类别下的子分类 Story 为 Article 下的子分类 层次关系: 0 - 2 - 3 - 4 这样就可以简单实现无限分类的数据库的设计了 使用: 给出Id 获取到它的父类别和所有子类别 Function getParentCategory($Id){ $sql = "select * from Category where Id = (select Cate_Parent_Id from Category where Id = $Id)"; $rs = mysql_query($sql,$conn); ...... //省事期间,给出伪代码吧 if(记录不存在 或者 $Id = 1){ return false; //无父级或不存在 }else{ return 查询出的父级数据数组; } } Function getChildCategory($PId){ $sql = "select * from Category where Cate_Parent_Id = $PId"; 存在则返回数据数组 否则返回false } 上面只是简单说明下大致思路.. php,J2ee的我没手写过,都是通过支持ORM的MVC框架去配置出来的. asp的倒是写过,需要的话,可以发你 只要逻辑关系整清楚了,就不难了...至于页面展示,可以用JS或者AJAX
❺ sql 查询:无限极分类,获取父类下所有子类
这问题很有趣哦!很多公司面试经常提到!有三种办法:
1.父类子类都各自建表(不推荐)
2.子类父类同在一张表(推介)
3.还有一种做法记不清了。
下面说说第二种做法吧!
你可以在数据库中建一张表都拥有以上的字段,然后在hibernate配置文件里配置一对多的关系,自己类对自己类做一对多的关联,具体配置你可以在一些论坛网站上搜到的。然后查询时你只要按id=父类的那个id去查一遍就全出来了.