473,386 Members | 1,830 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,386 software developers and data experts.

Many to Many

I'm setting up a many-to-many relationship between an instructors
table and a class table. 1 Instructor can have many classes. 1 Class
can be held by more then one instructor. I'm using a bridging table
between the 2.

I placed a 3rd table between them that consists of (ID, Instructor_ID,
Class_ID). The Instructor_ID and Class_ID were set to allow
duplicates. These were then linked back to the Instructor and Class
table.

In the form for the class, you may now select an instructor from a
combo box and click on add. The 3rd table is then updated with the
instructors ID and the Class ID. You may do this for multiple
instructors.

The problem I am having is that if you select an instructor, and then
hit add twice, they will be added to the class twice.

Is there a way of setting up some form of protection in the table
itself without having to resort to VBA to scan the table before you
add someting? Can you make the combination of field 2 and field 3 a
unique key?

I'm a bit stumped, as I don't do a lot of work in access and have only
taught myself what I needed to know at the time. So I don't have the
experience to know if this is a simple problem that I've never had to
deal with before.

Thanks.

Craig.
Nov 12 '05 #1
3 2908
2 possible answers:

1. Get rid of the ID column in the bridging table and then turn the other
two columns into a joint primary key (do this in table design by pasting
over both fields and then right click and select primary key)

2. Create a new query, go into SQL View (View, SQL View), then paste the
following code in and run the query:

ALTER TABLE tbBridging ADD CONSTRAINT UQ_Instructor_IDClass_ID UNIQUE
(Instructor_ID, Class_ID)

(Remember to replace tbBridging with the name of your bridging table)

Either of these will throw a trappable error if a duplicate is entered.
Hope at least one is useful.

~Ben

"jc3k" <sp***@hotmail.com> wrote in message
news:13**************************@posting.google.c om...
I'm setting up a many-to-many relationship between an instructors
table and a class table. 1 Instructor can have many classes. 1 Class
can be held by more then one instructor. I'm using a bridging table
between the 2.

I placed a 3rd table between them that consists of (ID, Instructor_ID,
Class_ID). The Instructor_ID and Class_ID were set to allow
duplicates. These were then linked back to the Instructor and Class
table.

In the form for the class, you may now select an instructor from a
combo box and click on add. The 3rd table is then updated with the
instructors ID and the Class ID. You may do this for multiple
instructors.

The problem I am having is that if you select an instructor, and then
hit add twice, they will be added to the class twice.

Is there a way of setting up some form of protection in the table
itself without having to resort to VBA to scan the table before you
add someting? Can you make the combination of field 2 and field 3 a
unique key?

I'm a bit stumped, as I don't do a lot of work in access and have only
taught myself what I needed to know at the time. So I don't have the
experience to know if this is a simple problem that I've never had to
deal with before.

Thanks.

Craig.

Nov 12 '05 #2
"Ben Eaton" <be************@hotmail.com> wrote in message news:<bn***********@news.wplus.net>...
2 possible answers:

1. Get rid of the ID column in the bridging table and then turn the other
two columns into a joint primary key (do this in table design by pasting
over both fields and then right click and select primary key)


Yep. This did it. To work in with some other code already there I
had to leave the ID in there. But I removed it as a primary key. I
didn't know about the joint primary key thing. I feel silly :)

Craig.
Nov 12 '05 #3
Hi.

Another option would be to set up a multifield unique index on the 2 keys of
the middle table.

While in design mode on the middle table, click on top bar View, Indexes...

A 'Indexes' pop up window displays the indexes.

Enter a new index name in the first column. on the same row in the second
column, select key from left table.
On the next row in the second column, select key from right table.
At bottom of the window select 'Yes' for unique.
That's it!


"jc3k" <sp***@hotmail.com> wrote in message
news:13**************************@posting.google.c om...
I'm setting up a many-to-many relationship between an instructors
table and a class table. 1 Instructor can have many classes. 1 Class
can be held by more then one instructor. I'm using a bridging table
between the 2.

I placed a 3rd table between them that consists of (ID, Instructor_ID,
Class_ID). The Instructor_ID and Class_ID were set to allow
duplicates. These were then linked back to the Instructor and Class
table.

In the form for the class, you may now select an instructor from a
combo box and click on add. The 3rd table is then updated with the
instructors ID and the Class ID. You may do this for multiple
instructors.

The problem I am having is that if you select an instructor, and then
hit add twice, they will be added to the class twice.

Is there a way of setting up some form of protection in the table
itself without having to resort to VBA to scan the table before you
add someting? Can you make the combination of field 2 and field 3 a
unique key?

I'm a bit stumped, as I don't do a lot of work in access and have only
taught myself what I needed to know at the time. So I don't have the
experience to know if this is a simple problem that I've never had to
deal with before.

Thanks.

Craig.

Nov 12 '05 #4

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

Similar topics

8
by: Greg | last post by:
Hello, I've to manage many 'table' (having same scheme) on the same server. And I ask myself what could be the best to do (and if you know, why) : Creating as many database (the name would...
3
by: Mikey | last post by:
Hi all. In the process of trying to figure this thing out, I've been doing the old "stand around in the store and read as much as possible before you look like a derelict" thing. This time, with...
2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
5
by: oNLINE bUDDY | last post by:
How can you reverse a many-to-many XML structure between 2 tags? Lets say we have a books/author XML file. A book can have many authors. <book1> <Author1> </Author1> </book1>
2
by: Megan | last post by:
hello everybody, i know this is a very long post, but i wanted to provide as much detail as possible. quick overview- i want to create a couple of many to many relationships and am wondering...
1
by: Johnny Meredith | last post by:
Hi, I'm building a database that, once a year, generates surveys that are emailed to people in our organization. The recipients of the surveys are managers of various departments. The emails...
1
by: Phil W | last post by:
Hello, I have set up my database in access using many to many relationships (it's the good ol' books and authors one again). I've actually extended it to include other people who contribute in...
13
by: the other john | last post by:
The trouble currently with 3 tables. I'm excluding non-relevant fields... tbl_users PK_user_ID tbl_developers PK_developer_ID FK_developer_user_ID FK_developer_project_ID
1
by: radiodave | last post by:
I don't know how to ask this question but I'll try: I'm making a database (Access 2003) for an Opera buff. I have tables related like: each Opera has many Productions (Madame Butterfly has an...
11
by: RobertJohn | last post by:
Hi all I am using Access 2007 to start a small home library application, and so far it has two tables. 1. Books, with fields Book_ID (Primary Key) and Title, and 2. Authors, with fields...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...

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.