易截截图软件、单文件、免安装、纯绿色、仅160KB

如果写递归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)



引用
SQL codeinsertinto 表2select*from 表1 awherenotexists
(select1from 表2 bwhere a.id=b.idand a.parentid=b.parentidand a.name=b.name)

可以尝试

哦 效率啊效率

原来这样真的可以。。想了。没


相关问答:

求一条oracle多表查询的sql,求高手们不吝赐教~

table1:
uID    uName
1      小李 
2      小张

table2:
pID  uID  type
1    1    H1
2    ......

Sql排序 - MS-SQL Server / 基础类

我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......

数据窗口动态修改Sql - PowerBuilder / DataWindow

为了满足数据查询的速度问题,我将一张数据量大的学生表按年度分成多个表
students_2008, students_2009然后我又做了一个模板表students_template,模板表中的字段和students_2008, students_2009一样,只不过是一个 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号