免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4912 | 回复: 8
打印 上一主题 下一主题

关于unique index问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-14 14:25 |只看该作者 |倒序浏览
请教一个问题。

2> create unique nonclustered index cntr_idx1

on cntr (

          disc_vv_c,

          disc_cell_locn_n,

          disc_htch_deck_c,

          disc_stw_seq_n,

          cntr_n_c )
3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15>
16> go
Msg 1505, Level 16, State 1:
Line 2:
Create unique index aborted on duplicate key.  Primary key is '<NULL>, " ", " ",
1, "TRLU 2807128"'

提示说重复健,

1> select count(*) from cntr where cntr_n_c="TRLU 2807128"
2> go

-----------
           1

(1 row affected)

看这个结果,应该没有重复的阿。
那位能给解释一下

论坛徽章:
1
2017金鸡报晓
日期:2017-01-10 15:19:56
2 [报告]
发表于 2009-07-14 15:28 |只看该作者
select disc_vv_c, disc_cell_locn_n, disc_htch_deck_c, disc_stw_seq_n,cntr_n_c
from cntr
group by disc_vv_c, disc_cell_locn_n, disc_htch_deck_c, disc_stw_seq_n,cntr_n_c
having count(*)>1

论坛徽章:
0
3 [报告]
发表于 2009-07-14 15:33 |只看该作者
3> select disc_vv_c, disc_cell_locn_n, disc_htch_deck_c, disc_stw_seq_n,cntr_n_c
from cntr
group by disc_vv_c, disc_cell_locn_n, disc_htch_deck_c, disc_stw_seq_n,cntr_n_c
having count(*)>14> 5> 6>
7> go
disc_vv_c disc_cell_locn_n disc_htch_deck_c disc_stw_seq_n cntr_n_c
--------- ---------------- ---------------- -------------- -------------

(0 rows affected)
1>

谢谢版主的回复,这是个bug?

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-20 06:20:00
4 [报告]
发表于 2009-07-14 16:26 |只看该作者
When you create an index with the unique option, if there is a
duplicate key value or if more than one row contains a null value, the
command is aborted and Error 1505 is raised。
disc_vv_c有NULL值

论坛徽章:
0
5 [报告]
发表于 2009-07-14 16:55 |只看该作者
disc_vv_c字段是有空值,但是我不理解为什么和这个有关系。

ps:刚才我把字段的顺序改变了一下,居然创建成功。不知道为什么?

论坛徽章:
1
2017金鸡报晓
日期:2017-01-10 15:19:56
6 [报告]
发表于 2009-07-14 18:16 |只看该作者
ASE什么版本?

论坛徽章:
0
7 [报告]
发表于 2009-07-14 18:26 |只看该作者
Adaptive Server Enterprise/11.9.2/1031/P/Sun_svr4/OS 5.5.1/FBO/Fri Aug 14 06:26:45 1998

论坛徽章:
0
8 [报告]
发表于 2009-07-21 12:13 |只看该作者
看上去是第一列有空值造成的

论坛徽章:
0
9 [报告]
发表于 2009-07-28 14:01 |只看该作者
因为检查uniqueness的时候实际用到的key只有前4个,所以你这个情况前4个key都是有重复的,即使第5个不重复也没有什么用,因为这样index的作用已经很小了,好的办法就是改变你key的顺序,这可以说是个bug。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP