qingcheng_yuan 发表于 2009-07-14 14:25

关于unique index问题

请教一个问题。

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)

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

chuxu 发表于 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

qingcheng_yuan 发表于 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?

echoaix 发表于 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值

qingcheng_yuan 发表于 2009-07-14 16:55

disc_vv_c字段是有空值,但是我不理解为什么和这个有关系。

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

chuxu 发表于 2009-07-14 18:16

ASE什么版本?

qingcheng_yuan 发表于 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

ggpl 发表于 2009-07-21 12:13

看上去是第一列有空值造成的

shakeone 发表于 2009-07-28 14:01

因为检查uniqueness的时候实际用到的key只有前4个,所以你这个情况前4个key都是有重复的,即使第5个不重复也没有什么用,因为这样index的作用已经很小了,好的办法就是改变你key的顺序,这可以说是个bug。
页: [1]
查看完整版本: 关于unique index问题