热门搜索
-
SQLServer树形表非循环递归查询的实例详解
很多人可能想要查询整个树形表关联的内容都会通过循环递归来查...事实上在微软在SQL2005或以上版本就能用别的语法进行查询,下面是示例。--通过子节点查询父节点WITHTREEAS(SELECT*FROMAreasWHEREid=6--要查询的子idUNIONALLSELECTAreas.*FROMAreas,TREEWHERETREE.PId=Areas.Id)SELECTAreaFROMTREE--通过父节点查询子节点WITHTREEAS(SELECT*FROMAreasWHEREid=7--要查询的子idUNIONALLSELECTAreas.*FROMAreas,TREEWHERETREE.Id=Areas.PId)SELECTAreaFROMTREE通过子节点查询父节点查询结果为:修改代码为--通过子节点查询父节点declare@areavarchar(8000);WITHTREEAS(SELECT*FROMAreasWHEREid=6--要查询的子idUNIONALLSELECTAreas.*FROMAreas,TREEWHERETREE.PId=Areas.Id)sel...
数据库操作教程 2022-09-23 18:01:19