日期:2014-05-18  浏览次数:20519 次

问一个datetime字段类型创建unique clustered index错误
create unique clustered index id_updated on v_aaa(updated);老是提示记录重复无法创建的错误。
里面的数据明明没有重复啊。
updated值如下
2001-12-12 00:11:25.012
2001-12-12 00:11:25.013
2001-12-12 00:11:25.014
2001-12-12 00:11:25.015
2001-12-12 00:11:25.016
2001-12-12 00:11:25.017
2001-12-12 00:11:25.018



数值就是上面列出的值,明明每一都不同啊,但是老是提示错误,晕倒。


------解决方案--------------------
微秒数,精确度不够.不建唯一索引,直接插入后运行一下,你就知道了:
SQL code
create table tb(dt datetime)
insert into tb select '2001-12-12 00:11:25.012'
insert into tb select '2001-12-12 00:11:25.013'
insert into tb select '2001-12-12 00:11:25.014'
insert into tb select '2001-12-12 00:11:25.015'
insert into tb select '2001-12-12 00:11:25.016'
insert into tb select '2001-12-12 00:11:25.017'
insert into tb select '2001-12-12 00:11:25.018'
go
select * from tb
/*
dt
-----------------------
2001-12-12 00:11:25.013
2001-12-12 00:11:25.013
2001-12-12 00:11:25.013
2001-12-12 00:11:25.017
2001-12-12 00:11:25.017
2001-12-12 00:11:25.017
2001-12-12 00:11:25.017

(7 行受影响)
*/
go
drop table tb