求:sql 语句 - MS-SQL Server / 基础类
数据库db1的A表,和DB2的B表,表结构相面,PRIMARY KEY 为ID,要求将A表中B表没有的数据写入到B表中。
SQL code:
INSERT B
select * from db1..A a
WHERE NOT EXISTS(SELECT 1 from db2..B WHERE a.ID=b.ID)
SQL code:
insert db2..b
select * from db1..a t
where not exists(select 1 from db2..b where id=t.id)
SQL code:
--同服务器
insert db2.dbo.b
select *
from db1.dbo.a t
where not exists
(select 1 from db2.dbo.b where id=t.id)
SQL code:
INSERT B
select a.* from db1.dbo.A a join db2.dbo.B b on a.id=b.id
WHERE b.id is null
谢谢各位!
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
id url rank ......
我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......