如果写递归sql语句 - MS-SQL Server / 应用实例
有两个同样的表结构
表结构如下:
id(序号) parentid (父结点序号) name(结点名称)
表1 记录 1 0 aaa
2 0 bbb
3 1 ccc
。。。。。。
表2 记录
1 0 bbb
2 0 xxx
。。。。
表1与表2都是树状结构记录。现需要将表1记录导入到表2中 ,表2中已经有部分记录,有些记录与表1中记录相同。
现需要将表1中的记录导入到表2中,需要判断表2中没有表1记录的需要全部导入,并且树状结构和表1中的结构一致。
用存储过程也可以。谢谢。
MRAK 回去再看
顶下
SQL code:
insert into 表2
select * from 表1 a where not exists
(select 1 from 表2 b where a.id=b.id and a.parentid=b.parentid and a.name=b.name)
可以尝试
哦 效率啊效率
原来这样真的可以。。想了。没
相关问答:
table1:
uID uName
1 小李
2 小张
table2:
pID uID type
1 1 H1
2   ......
我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......
为了满足数据查询的速度问题,我将一张数据量大的学生表按年度分成多个表
students_2008, students_2009然后我又做了一个模板表students_template,模板表中的字段和students_2008, students_2009一样,只不过是一个 ......