Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Previous article   Next article back to categoryAccess articles

One To Many Relationships In Access

Fri 25th March 2011

What is a One-To-Many relationship? This walk through examines a relationship in Access tables between Robbie Williams (one) and his seven studio albums (many).
Take That were recently voted Best British Group at the Brit Awards, two decades after they released their debut single. This prize was hailed as a complete turnaround by those fans who had been devastated back in 1995 when the band split. After the TV news cameras' film of sobbing girls had faded from our TV screens, the band members took stock of their situations and the most prominent post-Take That solo career belonged to Robbie Williams. But why am I telling you this?

When Robbie released his debut album Life Thru a Lens in 1997, I was the manager of a video rental store that also hired out CDs and the way that information relating to these CDs was stored serves as a good example of how relationships work in Access, although I will be referring to versions from this side of the millennium.

The first database to set up will be called Albums and it will consist of just two fields, the album ID and the title. To do this I create a new database and open it in Design View. I enter the title of the first field as Title ID and from the Data Type menu I select AutoNumber to give each album its own unique identifying number. I highlight this field and from the toolbar in pre-2007 versions, or the Design ribbon in post-2007 versions, I click on the key icon and in so doing I have made this field the Primary Key, which allows me to access the details of each album by its unique identifying number. I name the next field Title and from the Data Type menu this time I select Text.

With my fields set I switch to Datasheet view and enter the titles of all of the albums in stock. I need only type in the titles, as the Title ID field will number the albums automatically. I save the database and put the kettle on.

Now I create my second database, this time called Artists. As before I go into Design View and the first field I create is Artist ID. Again I select AutoNumber to list the artists and I make this field my Primary Key. The next field gets the title Artist and I enter the artists' details and save as before.

I now have two databases relating to the CD stock in the store, and I want to create a relationship between them. I need to go back into my Albums database in Design View and add another field. I will call this field Artist ID and from the Data Type menu I will select Number. I enter the ID for each artist and then save and close, and I now have an Artist field in my Album table.

On the Database Tools ribbon I click on Relationships and this opens up the Show Table dialog box. I click on my two databases and add them to the dialog box and I see that they have both appeared on the Relationships screen. Now I close the Show Table dialog box and work on the relationship between my two databases.

To create the relationship I click on the Artist ID in my Album database and drag it across to the Artist ID in my Artist database, and then release it. The Edit Relationship box will then come up to confirm that I am relating the Artist ID in the Artist table with the Artist ID in the Album table. I check the Enforce Referential Integrity box, which sounds quite technical but it simply means that I will not be allowed to delete a record from the Artist table if the same details are present in the Albums table.

The dialog box also shows that I am creating a One-to-Many relationship. This means that each record in the Artist table may have several linked records in the Album table but each record in the Album table will have only one corresponding record in the Artist table. For example, our friend Robbie released seven studio albums before returning to the Take That fold. If I stocked his entire repertoire, he would be linked to seven records in the Album table, but each of those albums would only be linked to Robbie Williams in the Artists table.

I click on Create and the two tables on the screen become linked, and the One-to-Many relationship id signified by a figure 1 at one side of the link and a double zero at the other. I save and close and the open the Albums table and, in the new Artist ID field I just added, I enter the artists' ID from the Artist table.

Now if someone comes in saying they enjoyed Life Thru a Lens and they would like to listen to more stuff from this artist, then I can access our entire Robbie Williams stock by using the relationship I set up above.

Relationships in Access can be a lot more complex than the example I have given, but they are an extremely useful tool in the vast Access toolbox. Learning more about how relationships work would be a worthwhile step. You can Take That as read.

Author is a freelance copywriter. For more information on microsoft access courses london, please visit https://www.stl-training.co.uk

Original article appears here:
https://www.stl-training.co.uk/article-1591-one-many-relationships-access.html

Back to article list

Publication Guidelines

  • You have permission to publish this article for free providing the "About the Author" box is included in its entirety.
  • Do not post/reprint this article in any site or publication that contains hate, violence, porn, warez, or supports illegal activity.
  • Do not use this article in violation of the US CAN-SPAM Act. If sent by email, this article must be delivered to opt-in subscribers only.
  • If you publish this article in a format that supports linking, please ensure that all URLs and email addresses are active links, without the rel='nofollow' tag.
  • Software Training London Ltd. owns this article. Please respect the author's copyright and above publication guidelines.
  • If you do not agree to these terms, please do not use this article.

Access courses in London and UK wide.

» Next available dates

 

Training courses

 

London's widest choice in
dates, venues, and prices

Public Schedule:

Buy now / Live dates

On-site / Closed company:

Get quote

Testimonials

More testimonials

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.17 secs.