首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

当提示:违反了PRIMARY KEY 约束 。不能在对象 '表tab1' 中插入重复键。小弟我想知道是哪条数据违反了

2012-01-31 
当提示:违反了PRIMARY KEY 约束 。不能在对象 表tab1 中插入重复键。我想知道是哪条数据违反了表tab1字段1

当提示:违反了PRIMARY KEY 约束 。不能在对象 '表tab1' 中插入重复键。我想知道是哪条数据违反了
表tab1
  字段1   name
  字段2   address
name是主键  

表tab2表结构与表tab1表结构一致
我将tab2的数据导入到表tab1中
insert   into   tab1   select   *   from   tab2
tab2.name有可能在tab1中有
当提示   违反   primary   key   约束...   不能插入重复键时
我想知道是哪条数据重复了,就是想得到name的值!

[解决办法]
select a.* from tab1 a ,tab2 b where a.name = b.name
[解决办法]
就是找tab1,tab2都有的数据:

这样也可以

select * from tab1 a where exists(select 1 from tab2 where a.name = name)
[解决办法]
楼上的就可以了
[解决办法]
select a.* from tab1 a inner join tab2 b
on a.name = b.name

热点排行