22,298
社区成员
发帖
与我相关
我的任务
分享
IF OBJECT_ID('LI1') IS NOT NULL
DROP TABLE LI1
IF OBJECT_ID('LI2') IS NOT NULL
DROP TABLE LI2
create table LI1(name int,type int,[file] varchar(100))
create table LI2(name int,type int,[file] varchar(100))
insert into LI1
select 2,22,'33.rar' union all
select 1,11,'22.rar'
insert into LI2
select 2,22,'33.rar' union all
select 4,44,'44.rar' union all
select 5,55,'55.rar'
--执行操作
INSERT INTO LI1([NAME],[TYPE],[FILE])
SELECT S.[NAME],S.[TYPE],''
FROM LI2 S
WHERE CHECKSUM(*)
NOT IN (SELECT CHECKSUM(*) FROM LI1)
SELECT * FROM LI1
--删除测试环境
DROP TABLE LI1
DROP TABLE LI2 /*结果
name type file
2 22 33.rar
1 11 22.rar
4 44
5 55
/*create table [log]([name] int,[type] int,[file] varchar(10))
insert into [log] select 2,22,'33.rar'
create table [file]([name] int,[type] int,[file] varchar(10))
insert into [file] select 2,22,'33.rar'
insert into [file] select 3,33,'44.rar'
insert into [log]([name],[type]) select [name],[type] from [file] a where not exists
(select 1 from [log] where [name]=a.[name] and [type]=a.[type])
select * from [log]
go
drop table [log],[file]
/*
name type file
----------- ----------- ----------
2 22 33.rar
3 33 NULL
*/insert into log([name],[type]) select [name],[type] from file a where not exists
(select 1 from log where [name]=a.[name] and [type]=a.[type])