Blog

The Primary Key Feature In Ms Access

The Primary Key Feature In Ms Access
Blog

The Primary Key Feature In Ms Access

Why Do We Need the Primary Key Feature In Ms Access

Why do we need the Microsoft Access Primary Key feature? It is a way of uniquely identifying any individual row of data. In a set of data, if you start thinking of cars or items that have naturally occurring primary keys. They’re not natural because we have given them identifying keys.

So, a car has a registration number, and that’s a unique reference to that Vehicle. With the registration number, you know everything about that vehicle, such as the date of manufacturing.

Registration, color, engine size, mileage history, in short, everything is attached to that Microsoft Access primary key, which is the registration number of that product. Product usually provided with a product ID of some kind. Now, when I use the word ID, an ID can contain numbers and letters. It’s not just a numerical ID, and a product ID could potentially have both original and customized. We don’t have a naturally occurring ID number; we don’t have a primary key.

For Example:

We’ve got Mr. Gaetano Vaccaro, but int our table, we could have two Mr. Gaetano Vaccaro. How would I then distinguish between them? If I want to edit their record potentially, I could say it’s Mr. Gaetano. But he lives at a different address, and I know families that have the same name for the father and the son. And they live at the same address. It’s not that unusual so, I have a problem then. I can’t distinguish between these people based on their names.

It is because they have exactly the same name. I can’t distinguish them based on their address because they have the same address. Maybe they started on a different day; that would be pretty helpful. But I’m sorry to say both of them didn’t start on the same day. Just because they both work for the same company, it has the same number of employees. So, essentially make them live these two people as the same. But they’re not the same; they are different people.

The Primary Key Feature In Ms Access 1

We tend to add in other descriptors to try and distinguish. If you’ve got two friends called john and they both got the same surname. So, john smith, you would add in another descriptor, perhaps one of them is bold, and one of them is large. One of them is a butcher, and the other one’s a baker. So, you have another way of splitting the Data that is not really easy to work with. When you’re dealing with electronic databases as we have here so, what tends to happen, and you’ll know from your own experience.

Use of NHS Number In The Microsoft Access Primary Key Feature

Wherever your data is stored electronically, you are given a unique reference, so that could be a national insurance number that can be an NHS number as well. It could be a policy number again, I use the word number, but it should be a reference. In that number, you can see a mixture of numbers and letters. So, what we need to do in our databases is to have some way of uniquely identifying.

And the easiest way to do that would be to give every new customer an ID. So, we need to go back into the design; we need a new field. I’m going to insert it at the top here.

Select that row, insert an extra row and sensibly call my new field customer ID. Now that ID can be a numeric value, it’s not a problem, or it could be a short text, in which case I’d have to think of a system for adding new people.

Or access could just make life so much easier for me, and I could use the built-in field. The auto-number gives one to the first record, two to the second record, three to the third record, etc.

As it goes through, if you delete a record, that number is then not reassigned; it’s effectively lost.

Use of Customer ID in the Primary Key Feature in MS Access

So, if I add in custom ID as the auto number, I am giving my table a field that it can use as a unique reference and easily allow access to create that unique reference. What I haven’t done yet is actually told access that this field will be the primary key.

So, I select the field, and there’s a big button on the top primary key. It’s also on the right-click primary key. Whichever I go for, I’m going to get a little key in the column. So, you can see there’s a little key I then save my table and go back to view.

The Primary Key Feature In Ms Access 2

And see that my first customer has one as their ID; my second customer has two. Now I have even thought their data is exactly the same along a way of uniquely identifying, which is Gaetano Vaccaro. Let’s add someone else in, so Mrs., as soon as I start typing in the first field after the auto number field.

Importance of the Microsoft Access Primary Key Feature

The Primary Key feature in Ms Access is important; because I can’t type in that field, it’s then given the next number. It’s giving it three, so I’m going to misses sally bell. She lives in the big house long lane small tune in the south. She started with us, not on the first of May, but let’s go; she started in first April. They have three employees, and she’s life, so doing forget the space tab brings me down to the next row. And I’m ready for another new customer.

So, that’s how the primary key access is pretty keen on the primary key.

If you try to create a table without one, it will prompt you to add one; as you saw in the first lesson when we created this table, that box pops up. If you then say yes, it will actually add a new field called ID. And give it the data type of auto-number so, if you don’t have your own idea of a primary key and cars, that would be the Registration number.

They might have a special product number etc. If you don’t have any idea, access gives you this great way of doing it, which is the auto number field.

There’s auto numbering starting from one and just adding one. For each person, every table needs a primary key. So, at the moment we’ve only got one table, but we will be adding other tables. Each of those tables will need its own primary key. They might turn out to be just auto numbers generated by access.

Auto Numbering in the Microsoft Access Primary Key Feature

That’s great; it just gives us one way of saying that’s the record I want it one. So, that if we try to do anything to that record like delete it, or edit it, access has no way of getting that record wrong because it says well. It’s recorded with ID2; there’s only one record with ID2. Let’s delete it, let’s edit it, let’s change whatever we’re going to change in. That’s why the primary key is vitally important.

Full Excel Course Certification $7 $147Enroll Now
×

 

Hello!

We are available on WhatsApp. To Start a chat click below and we'll get back to you as soon as possible

× How can I help you?