473,385 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Junction Tables

ken
Hi,
Do Junction Tables need ID fields with Primary keys? For example if you
store employee ID, employee name, Company ID, Company name. As you can
see no field here can be a primary key since all of the columns will
have repeatable values. So does one need to put in an autonumber field
and make it a primary key?

thanks

Nov 13 '05 #1
5 2759
assuming
many company IDs, many employee IDs
assigned employee IDs

tblCompany
companyId
companyName

tblEmployee
pkId (autonumber)
employeeId
employeeName
companyId

lets you change the employeeId if required

Nov 13 '05 #2
ken
I assume pkid is just a column with no value other then to have it be
an autonumber primary key correct? Anotherwords you recomend having
primary keys in all tables? Will it be practical to do this even though
I may delete some records from these columns in the future?

Nov 13 '05 #3
While you can use an Autonumber field, you really want employee id and
company id BOTH to be at least a unique index, to prevent duplicate entries
from being insert. As well, since Employee Name and Company Name can be
derived when you know the Ids, they shouldn't be stored in the Junction
table.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"ken" <ge****@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hi,
Do Junction Tables need ID fields with Primary keys? For example if you
store employee ID, employee name, Company ID, Company name. As you can
see no field here can be a primary key since all of the columns will
have repeatable values. So does one need to put in an autonumber field
and make it a primary key?

thanks

Nov 13 '05 #4
An autonumber primary key is unlikely to be an encumbrance or to create
slowdown for a linking (or junction) table.
It could be useful when we want to classify the relationship link.
That is we might have another table categorizing employer-employee
relationships, perhaps something like, hourly, eligible for vacation
pay, eligible for severance, health benefits, whatever. The primary key
of the employer-employee table could then be used in another table
linking that to the employer-employee relationships table in a many to
one mapping. (A one to many relationship is quite impossible.)
In some cases bound forms and recordsets will not update unless a
unique index exists and can be found and identified by whatever
technology is being used to make the connection or doing the binding. A
Primary Key is an easy way to be sure that this requirement will not
jump up and "gotcha" at some inopportune time.
All my tables have autonumber primary keys, or their equivalent.

I would not make a unique index on employer pk-employee pk, but I might
add a timestamp kind of column. With such a column we would have a
record that John Doe worked for Apple from whenever to a certain date,
and then began to work for Hewlett Packard.

Nov 13 '05 #5
yes, pkId is such a column....
I don't always use a 'autonumber' field as a key, it depends on the
data

in most applications, the employeeId field is used as a foreign key in
other tables (vacations, scheduling, payroll), so deleting it out of
tblEmp means deleting its records from all the other tables too

usually, for tracking purposes, business rules would prevent the
deletion of the data, in that case, I'd add 'start date', 'end date'
fields to the table to track when the employeeId is valid

but if you can delete the record and if you use autonumber keys, and
assuming you have keys 1,2,3,4,5,

if you delete 3, and you add a new record, the list is 1,2,4,5,6
then record '3' is gone until you copy the existing table into a new,
duplicate table (tblEmpNew) and rename tblEmpNew to tblEmp
ken wrote:
I assume pkid is just a column with no value other then to have it be
an autonumber primary key correct? Anotherwords you recomend having
primary keys in all tables? Will it be practical to do this even though
I may delete some records from these columns in the future?


Nov 13 '05 #6

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

Similar topics

1
by: mksql | last post by:
As an example, I am building an authentication mechanisim that will use data in the 3 left tables to determine rights to objects in a destination table, diagrammed below. In this structure,...
3
by: Good Man | last post by:
Hi there I've designed some web applications that are fairly small scale (thousands of users) but my MySQL tables are indexed well and they all run quickly and efficiently. Today I decided to...
8
by: Marcy | last post by:
I am trying to build a database to keep track of training topics completed by people in my department. Our department has a set of 37 training topics. There are 7 job classifications in the...
3
by: Kostas | last post by:
Hi all, I was wondering what's happening in a typical junction table where the primary key is the combination of two foreign keys from other tables. I suppose Access automatically creates a...
1
by: Riley DeWiley | last post by:
I have an application with two tables, A and B. Each has an autonumber unique ID field, plus other data. I have a junction table, AB, containing fields AID, BID, and Count (a number). AB has...
1
by: LurfysMa | last post by:
I am working on an electronic flashcard program. Most of the subjects are simple lists of questions and answers. Those seem to be working. Some of the "subjects" have "categories" of questions. ...
1
by: que576 | last post by:
I have created a junction table so that I can relate data from 2 other tables. Table 1 - Category Table (has the following fields with data) CatID (primary key) CategoryName CategoryStatus ...
1
by: bg_ie | last post by:
I'm designing a database with 3 tables called Function, Test and Scene. A Function has multiple Tests, but a Test has only one Function. A many to many relationship exists between Test and Scene...
3
by: dbertanjoli | last post by:
Hello, I have a questinarrie webform I use INSERT statement(s) to insert a new record in the User and Questions tables and then (HERE IS MY PROBLEM) I need to update my junction table...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.