473,569 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Index and Null values

Last week I posted about making a unique index on multiple fields to prevent
importing identical records twice. I still have trouble with the nulls in
the index. The only way that I can make it work is to make all the index'
fields required fields and set the allow nulls setting to false. But then
every field in the index should always have some kind of value, and I have
to put a default value like "0" in them or "empty". Is this indeed the only
way to make this index work or is it somehow possible to make a unique index
where the nulls are part of that index?
Thanks,
john
Sep 2 '06 #1
6 6222
"john" <jo**@test.comw rote in
news:lb******** ************@ca sema.nl:
Last week I posted about making a unique index on multiple
fields to prevent importing identical records twice. I still
have trouble with the nulls in the index. The only way that I
can make it work is to make all the index' fields required
fields and set the allow nulls setting to false. But then
every field in the index should always have some kind of
value, and I have to put a default value like "0" in them or
"empty". Is this indeed the only way to make this index work
or is it somehow possible to make a unique index where the
nulls are part of that index? Thanks,
john
You can set a default value for the field in the table design view.
You can also allow zero length strings.Use the two of them
together.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 2 '06 #2
"Bob Quintal" <rq******@sPAmp atico.caschreef in bericht >>
You can set a default value for the field in the table design view.
You can also allow zero length strings.Use the two of them
together.
Thanks. For the text fields I now have Allow Zeros set to True, Required to
Yes, and Default value to "". But this doesn't work for date fields. Does
that mean that I can't have an empty value for a date field and that I need
a default value for that like "01-01-1900"? Doesn't seems very pretty.
john
Sep 2 '06 #3
On Sat, 2 Sep 2006 07:59:06 +0200, "john" <jo**@test.comw rote:
>Last week I posted about making a unique index on multiple fields to prevent
importing identical records twice. I still have trouble with the nulls in
the index. The only way that I can make it work is to make all the index'
fields required fields and set the allow nulls setting to false. But then
every field in the index should always have some kind of value, and I have
to put a default value like "0" in them or "empty". Is this indeed the only
way to make this index work or is it somehow possible to make a unique index
where the nulls are part of that index?
Thanks,
john
Not sure I understand what you are trying to do but:

You can have a unique index (though not a primary one) which contains nulls,
just remember that each null which occurs is treated (at least in Access, not
all dbs do this) as a different value, ie the records

ab; null;
ab; null;

are regarded as being different (since (null=null) is false).

Empty is really a concept which applies to variants, it means it has not been
initialised. Though you can use Isempty() to see whether a non-variant has
been intitialised, this works because of type conversion. Null is the concept
which applies to table entries. If you assign Empty to a variable it gives 0
or "" etc as appropriate via the automatic type conversion.

HTH

Sep 2 '06 #4
Help me understand... it appears from what you write that you believe a
"unique index" means "unique except multiple records can have a Null"? In my
view, "unique index" means the field has to have a different value in every
Record (to identify the Record).

Allowing Nulls in a unique index would defeat that, notwithstanding the
purist definition of "Null" -- isn't equal to anything else, even another
Null. Searching the index on Null would return multiple Records if Nulls
were allowed. I also believe that using a Null String (zero-length string)
would defeat the purpose of unique index.

Larry Linson
Microsoft Access MVP

"john" <jo**@test.comw rote in message
news:68******** ************@ca sema.nl...
"Bob Quintal" <rq******@sPAmp atico.caschreef in bericht >>
>You can set a default value for the field in the table design view.
You can also allow zero length strings.Use the two of them
together.

Thanks. For the text fields I now have Allow Zeros set to True, Required
to Yes, and Default value to "". But this doesn't work for date fields.
Does that mean that I can't have an empty value for a date field and that
I need a default value for that like "01-01-1900"? Doesn't seems very
pretty.
john

Sep 2 '06 #5
I should make clear that a non-PK unique index _can_ be specified to allow
Nulls, but I still think it defeats the purpose.

Larry Linson
Microsoft Access MVP
Sep 3 '06 #6
Person, Larry,
From my original post:
"I've made an import macro to import bank transactions with queries. Those
transactions
don't have an ID_number when downloaded from internet. They get it when they
are added to the main transaction table in my database. When adding them I
would like to check if they haven't accidentally been added already, based
on account nr, date, amount of money, and payers info."

Sometimes one or two fields are blank so if the following record already
exists in my main transaction table:
account date amount payers info
1234564 01-01-2006 90 This field has no value
and the user would accidentally try to add it again, that should not be
possible.
In Paradox I was used to the fact that null is identical to null in another
record, so the unique index would refuse the double entry of the above
mentioned record.
thanks,
john
"person" <sn**@snappers. comschreef in bericht
news:6h******** *************** *********@4ax.c om...
On Sat, 2 Sep 2006 07:59:06 +0200, "john" <jo**@test.comw rote:
>>Last week I posted about making a unique index on multiple fields to
prevent
importing identical records twice. I still have trouble with the nulls in
the index. The only way that I can make it work is to make all the index'
fields required fields and set the allow nulls setting to false. But then
every field in the index should always have some kind of value, and I have
to put a default value like "0" in them or "empty". Is this indeed the
only
way to make this index work or is it somehow possible to make a unique
index
where the nulls are part of that index?
Thanks,
john
Not sure I understand what you are trying to do but:

You can have a unique index (though not a primary one) which contains
nulls,
just remember that each null which occurs is treated (at least in Access,
not
all dbs do this) as a different value, ie the records

ab; null;
ab; null;

are regarded as being different (since (null=null) is false).

Empty is really a concept which applies to variants, it means it has not
been
initialised. Though you can use Isempty() to see whether a non-variant has
been intitialised, this works because of type conversion. Null is the
concept
which applies to table entries. If you assign Empty to a variable it gives
0
or "" etc as appropriate via the automatic type conversion.

HTH

Sep 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22909
by: Aad Aldus | last post by:
Ik have created an index on a date field. 99% of all data in the table has a filled in date. 1 % is NULL When I do a select with clause ... WHERE ADATE IS NULL, Oracle does not use the index. Is this correct? or How can I force Oracle to use the index. Kind reagrds, Aad.
0
4295
by: stef | last post by:
Hi, I have a range partitioned (one partition = one month) table. On this table I have a local unique index and a local domain index (Oracle Text) on a CLOB column. I'm running Oracle 9.2.0.1.0 CREATE TABLE PAGES_4M ( LOADDATE NUMBER(8) NOT NULL,
4
1536
by: DC | last post by:
When a nonunique nonclustered index is built on top of a clustered index, is it guaranteed that the bookmark in the nonclustered index will be kept in the same order as the clustered index? Here's an example to demonstrate my question: CREATE TABLE indextest (col1 int NOT NULL,col2 int NOT NULL,col3 int,col4 int) ALTER TABLE indextest...
5
503
by: Gerard M. Operana | last post by:
unsubscribe
3
22618
by: Prince Kumar | last post by:
Is there any way I can define an Unique constraint or unique index which allows more than one null values for the same column combination in DB2? ie, If my index is defined on (col3, col4) where both columns allow nulls, I want col3 + col4 to be unique, if one or both the columns have values. If both columns have nulls, it should allow more...
14
5393
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why...
0
1186
by: Dennis Gearon | last post by:
Given: CREATE TABLE Usrs( usr_id SERIAL NOT NULL PRIMARY KEY, usr VARCHAR(64) NOT NULL UNIQUE ); CREATE TABLE Emails( email_id SERIAL NOT NULL PRIMARY KEY, email VARCHAR(128) NOT NULL UNIQUE );
7
2912
by: Cyberwolf | last post by:
Is there a way to set a primary index to ignore Nulls and if so how would I do it. I have already tried setting it so it is not a required field, but that does not work. It states that the field can not contain null values.
8
5553
by: shira | last post by:
I have done a fair bit of searching, but haven't yet been able to find an explanation as to why one would set "ignore nulls" to "yes" when creating an index. I understand what it does (I think), but I'm looking to understand what scenario might prompt either setting (yes or no). Any clarity you can provide is much appreciated! Thanks kindly.
6
4305
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B Alvin Leader
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.