Sqlserver Excel 导入数据时数据库主键不能重复导入的方法
发布时间:2020-12-12 14:38:47 所属栏目:MsSql教程 来源:网络整理
导读:1.将数据将Excel 文件中的数据导入到一张临时的数据库表中 2.将临时表中的数据导入到目标表中,并判有相同数据库插入 --目标表 create table order_detail( od_id nvarchar(50) primary key NOT NULL, od_price float NOT NULL od_outtime datetime NULL )?
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 )?(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |