开发者

How to create unique index in Access w/ integer fields that may be null?

I'm trying to create a unique multi-column index on a table in Access. Several of the fields I'll be using in the index are long integers. These fields may be blank开发者_如何学运维 in some records. I know that I can't allow actual NULLs because then I can't have unique records, e.g. if I try to build the table as follows:

Field1 (text),Field2 (integer),Field3 (text)
1:"a",56,"c"
2:"x",NULL,"f"
3:"x",NULL,"f"

then row 3 will be allowed (which I don't want) because the NULLs aren't really "equal" to each other.

I saw a solution where they set the following in Design View:

"Required"="Yes"
"Allow Zero Length"="yes"
"Default value"=""

But that won't help here because integers can't be set to "".

So, any ideas on creating a unique index under these circumstances?


I'm goin on general DB theory, but Acess could break the mold. Theory makes NULL fail to do as you wish because DBs take null to essentially mean "give up on evaluating". This leaves you to set a default value, like 0, -1 or minimum int for example, but that leaves you with fake, meaningless data--a very bad thing.

Can you add a surrogate field (say of string type) that is populated with the string representation of your integer? Not sure about Access, but triggers or calculated columns are two general DBMS options for doing this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜