关于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)
看这个结果,应该没有重复的阿。
那位能给解释一下 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 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? 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值 disc_vv_c字段是有空值,但是我不理解为什么和这个有关系。
ps:刚才我把字段的顺序改变了一下,居然创建成功。不知道为什么? ASE什么版本? Adaptive Server Enterprise/11.9.2/1031/P/Sun_svr4/OS 5.5.1/FBO/Fri Aug 14 06:26:45 1998 看上去是第一列有空值造成的 因为检查uniqueness的时候实际用到的key只有前4个,所以你这个情况前4个key都是有重复的,即使第5个不重复也没有什么用,因为这样index的作用已经很小了,好的办法就是改变你key的顺序,这可以说是个bug。
页:
[1]