微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sqlserver Excel 导入数据时数据库主键不能重复导入的方法

1.将数据将Excel 文件中的数据导入到一张临时的数据库表中

2.将临时表中的数据导入到目标表中,并判有相同数据库插入



--目标表
create table order_detail(
od_id nvarchar(50) primary key NOT NULL,
od_price float NOT NULL
od_outtime datetime NULL


-- 临时表
create table temp(
od_id nvarchar(50) primary key NOT NULL,
od_price float NOT NULL
od_outtime datetime NULL


select * from temp
select * from order_detail

insert into 目标表(字段1,字段2,字段3) select 字段1,字段3 from  临时表  where  不能重复的字段  not in (select 不能重复的字段 from 目标表 ) 

insert into order_detail(od_id,od_price,od_outtime) select od_id,od_outtime from  temp  where  od_id  not in (select od_id from order_detail ) 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐