Consider this table structure:
CREATE TABLE [TableA]
(
[PK_ID] int NOT NULL PRIMARY KEY,
[Name] text NOT NULL,
[FK_TableB] int NULL,
[FK_TableC] int NULL,
[Value] single NULL
)
I would like to create a unique index over Name
, FK_TableB
and FK_TableC
, so that the data in those 3 columns remains unique. Sadly, the 2 FK columns are nullable and Access automatically ignores NULLs in UNIQUE indexes, making this possible:
Name | FK_TableB | FK_TableC
----------+-----------+-----------
Text1 | NULL | NULL
Text1 | NULL | NULL
I respect Access for having its own believes about whether NULL is a checkable value, but in this case it's incredibly contraproductive. Creating such an index in SQL Server works perfectly well, and I would love to find a way in Access.
This is what I've tried (and failed) / considered so far:
Creating a Validation Rule that would check for the uniqueness through the COUNT-function.
- Access: "You shall not be able to use Aggregate Functions in your Validation rules."
Creating a Unique Index with the NZ-function, which would check for NULLs.
- Access: "You shall not be able to use any sort of function in your index."
Make the FK columns required and insert a default / NULL-like record to each of the related tables.
- A pain to maintain and bad practice.
Insert an additional column that concatenates each of the 3 columns and create UNIQUE index that would only check the new column.
- Redundancies and bad practice.
My colleague is considering creating a Table for each possible case:
- Non-nullable unique
Name
- Non-nullable unique
Name
andFK_TableB
- Non-nullable unique
Name
,FK_TableB
andFK_TableC
Is this the only solution I've got?