defining relationships in access (1 Viewer)

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
Hi,

I seem to be stuck on the simplest of tasks with both google and forum searches coming up with information that’s either too simple or too complex for my needs (not time wasted though because I’m learning all kinds of related stuff).

How do I join my tables with one-to-one relationships?

[edit] Doh, got this one now - by indexing without duplicates then saying all in one have to link to one in another:D

How do I define both fields in a linking table as composite or two field primary key?
 
Last edited:

KeithG

AWF VIP
Local time
Yesterday, 20:33
Joined
Mar 23, 2006
Messages
2,592
To define more than one field as a primary key open the talbe in design view and hold down ctrl and you can select more than one field.
 

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
Thank you, thank you thank you :D :D :D
I do believe I've just managed to create my first multi-table database database with appropriate indexing/duplication rules and correctly enforced appropriate relationships :D That piece of information was the missing link :D
 

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
:confused:

OK, I spoke too soon!

It seems to be all in order until I try and enter data :eek:

Maybe I could be helped here.

Just looking at two tables: tblNames and tblFileNames;
tblNames has two fields:
NameID,
Name.

tblFileNames has
FileNameID,
FileName_NameID
where the latter refers to tblNames.

The restrictions I've put are:
tblNames.Name is indexed (no duplicates)
tblFileNames.File_NameID is indexed (no duplicates)

The relationship has Enforced Referential Integrity where the Join Type is:
Include ALL records from 'tblFileNames' and only those records from 'tblNames' where the joined fields are equal.

The problem is I can't input data into tblNames because:
"You can not add or change a record because a related record is required in 'tblFileNames'.

This isn't right because whilst all FileName entries will refer to a name in tblNames, tblNames also will include names of people who do not have a corresponding file. I thought that's what I defined but something's obviously not right.:(

Any comment appreciated.
 

KeithG

AWF VIP
Local time
Yesterday, 20:33
Joined
Mar 23, 2006
Messages
2,592
Can you post your DB and I will have a look?
 

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
Thanks Keith
 

Attachments

  • absoprobDB.zip
    15.4 KB · Views: 157

KeithG

AWF VIP
Local time
Yesterday, 20:33
Joined
Mar 23, 2006
Messages
2,592
Sorry, I will have to look at your DB tommorrow when I get to work. I have a meeting for the rest of the day. I will post back tommorrow though. Good Luck!!
 

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
Thanks ceh,

I've been aiming for normalisation though obviously I've not got it right. It's certainly worth reading about it from another angle to try and get it to sink in!

Basically, there's only two kinds of textual data in this db. The rest is about using additional tables to try and logically connect them in an appropriate manner so I can get the information I want out.

Maybe some context will help. I've got thousands of sound files differing from each other in that each contains a name sung in one of (currently) 12 styles. The files are named using one spelling of the sung name (though other spellings of the name also need to refer to the same file). The actual files for each style are kept in a directory of the name of the style.

Not all names are available in every style.
Not all names are linked to file-names.

[edit]Maybe it would be sensible to add here what I mainly what the db to do!!
Given a name and a style, the db needs to give me an associated filename (if there is one) and to tell me if that filename exists in the given style.
I've actually got this working with my first attempt (in a work-aroundy way heavily relying on QuicKeys to trigger my queries) but I've got a boolean column for each style in my filenames table which is not normalised. Also I'm stuck when it comes to instances where everything is not hunky-dory. e.g. name not in db, name not associated to filename, no file available in requested style etc.
[/edit]

So...

The two tables with their fields for the basic text info. are:
tblNames.NameID
tblNames.Name
Only one entry for each name is permitted.

tblStyles.StyleID
tblStyle.Style
Only once should a particular style be entered.

In order to limit the number of sound files, only one file of each name for each style is permitted (regardless of the number of spellings) - and it makes sense that the spelling used is the same in every style.

That to me implies I need a third main table with a difinitive list of allowed file names:
tblFileNames.FileNameID
tblFileNames.FileName_NameID

My logic says though the file names are referring to a different entity (files not people), because they are the same names, they may as well refer to the names table.

This table should also not permit duplicates.

My aim is to to be as strict as possible in what's allowed so that it's harder to mess up the data by repeating e.g. putting in a name again if a user can't be bothered to check if it already exists (and therefore having to link it again to a file name etc.) That's why I'm aiming for a one-to-one relationship where there's not a reason for a one-to-many. Also, I get the impression that the tighter my ship in terms of data structure, the more likely I am to get my queries to work properly.

OK, so writing this down is helping. I've now realised that each name may point to only one file name and every file name points to at least one name, maybe these two tables can be linked directly by a one-to-many relationship for linking purposes (as well as the one to one relationship for the file names). On second thoughts, maybe I do need a linking table if I can't link two tables twice for two different reasons?!

The other part is about linking the styles to the file names. As this is a many-to-many relationship, there's a need for another table and I'd got the impression that this is where a composite key comes in. My logic (possibly, maybe probably flawed) says there's no need for a new primary key for this table as it's only going to be referred to in context of the 'parent' tables, the records' uniquness being defined by the combination of the two foreign keys. I'm sure I've read somewhere that using a composite key is the way forward here.

Please note that though I'm writing confidently here it's because it seems to make sense to me. I am still a newby though as despite a good few attempts over the last decade, I've yet to create a relational database that has been good enough to serve its purpose in a practical sense. I intend this to be the first so I'm trying to get it right. All suggestions, pointers to articles, disagreement with the way I'm going about it and assistance is welcome and very much appreciated.
 
Last edited:

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
Doh, just thought of a possible spanner in the works for my data structure which should be considered now even if not incorporated until another time.

Some names e.g. jean have two pronounciations (male French pronounciation and female English pronounciation). At the moment it's hit or miss for the few names this way (Sara British way and Sara American way being probably the most common) whether the name is pronounced correctly. This will need to be addressed adding new soundfiles and incorporating this into the db.

Maybe along with the data structure complications of having the same names for files and names, it's a case for renaming the files simply with index numbers (maybe even having all the files in one folder) This would work fine with the db but would be a pain to find a file to listen to (for checking, editing etc.) by visually scanning the folder.

More to think about:) ... but at least now's the time to be thinking - not when it's all up and running!
 
Last edited:

absoprob

Registered User.
Local time
Today, 04:33
Joined
Apr 22, 2006
Messages
14
I seem to have got the essentials right with the table structure now so I'm pressing on. The part I just can't get my head around is the issue of identically spelled names that sound different. I've added and linked in a pronunciation table without knowing how it could be used but it won't be used for now anyway - I can look at that another time.

Onwards... :)
 

Attachments

  • dbNnames_Filenames_Styles.zip
    52.1 KB · Views: 145

stevekos07

Registered User.
Local time
Yesterday, 20:33
Joined
Jul 26, 2015
Messages
174
Could you add a field with phonetic spelling? This could be added to your secondary table rather than a sound file, and can be related to the tblNames via a foreign key. You can have an unlimited number of "styles" for each "Name". Sound files will take up an enormous amount of data, particularly if it is likely that there will be a large number of records.

Also, I would avoid using "Name" as a field name, as it is a reserved word and could cause conflicts in your DB.

Just my 2c.
 

Users who are viewing this thread

Top Bottom