Debbie said:
The IDs are spelled the same in all tables.
Table ownersandriders
ownerriderID-autonumber
firstname-text
lastname-text
Table horses
horseID-autonumber
horsename-text-no lookup
ownerriderID-number-with lookup to ownersandriders table on ownerriderID,
Owner: [tblownersandriders].[FirstName] & " " & [LastName]
owner-text-with lookup to table ownersandriders on owner:
[tblownersandriders].[FirstName] & " " & [LastName]
I know this looks crazy, but I was very frustrated when entering data in
the tables and only seeing numbers.
You should not store values redundantly (is this what a lookup does? I
have no idea); instead, have only one place for everything. Joining
tables via queries to get the 'text' that goes with the 'number'. You
have chosen to use autonumber candidate/artificial keys so these joins
should be easy and efficient. You can create a VIEW of such a queries
that is 'logically' equivalent to a table e.g. may be subsequently
queried as if it were a table.
Here's some ideas for an alternative schema:
CREATE TABLE Horses (
HorseID INTEGER IDENTITY(1,1)
NOT NULL PRIMARY KEY,
HorseName VARCHAR(200) NOT NULL
)
;
What do riders and owners have in common? You may, now or later, want
to model trainers, breeders, agents, etc. So how about a Persons table
for their common attributes:
CREATE TABLE Persons (
PersonID INTEGER IDENTITY(1,1)
NOT NULL PRIMARY KEY,
FirstName VARCHAR(35) NOT NULL,
LastName VARCHAR(35) NOT NULL
)
;
Owners could be modelled as a relationship between a horse and a
person. The pairings will provide the primary key. If your business
rule is that a horse can only have one owner, then HorseID must have a
unique constraint (otherwise remove it). When a person ceases to become
an owner their association is removed from the Owners table and their
details will remain in Persons (without making them look like a rider).
You may want other columns e.g. ownership_start_date,
ownership_end_date, so that the rows are never removed, like a history
table (you'd need to make ownership_start_date part of the primary key
to model a owner buying a horse she previously already owned):
CREATE TABLE Owners (
HorseID INTEGER NOT NULL
UNIQUE
REFERENCES Horses (HorseID)
ON UPDATE CASCADE
ON DELETE CASCADE,
PersonID INTEGER NOT NULL
REFERENCES Persons (PersonID)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (PersonID, HorseID)
)
;
I won't attempt an Events table because I can't guess what an event is
(something that's sounds vague to me probably means something very
specific in the model) but I bet it has a column named EventID <g>.
I assume 'riders' can be defined as a person who rides a horse in an
event:
CREATE TABLE Rides (
EventID INTEGER NOT NULL
REFERENCES Events (EventID)
ON UPDATE CASCADE
ON DELETE CASCADE,
HorseID INTEGER NOT NULL
REFERENCES Horses (HorseID)
ON UPDATE CASCADE
ON DELETE CASCADE,
PersonID INTEGER NOT NULL
REFERENCES Persons (PersonID)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (PersonID, HorseID, EventID)
)
;
This isn't a complete solution, of course, but I hope it will give you
some ideas.
Jamie.
--