This session you will be taught that why you need one and how you get one. If we take the customers table that we’ve already created .We’ve added Mr. Gaetano Vaccaro let’s just hide the navigation pane for a moment what is it.

Why Do We Need The Primary Key Feature In Ms Access

Why do we need them well the Primary Key feature in Ms Access is a way of uniquely identifying any individual row of data. In a set of data now if you start to think of cars or items they have sort of naturally occurring primary keys. They’re not natural because we have given them but they occur. So, a car has a reg number and that’s a unique reference to that Vehicle. With the reg number you know everything about that vehicle date of manufacture year.

Registration color engine size mileage mot history Everything is attached to that primary key. Which is the reg number with a product. Product usually given 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. But certainly has both where the difficulty comes is with humans. We don’t have a naturally occurring ID number we don’t have a primary key so in our table here fylla på kontantkort article from billigastemobilabonnemang.

 For Example :

We’ve got Mr. Gaetano Vaccaro but in 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 well okay it’s Mr. Gaetano. But he lives at a different address but 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. So, i can’t distinguish between these people based on their name.

Because they have exactly the same name. I can’t distinguish them between based on their address because they have the same address. Maybe they started on a different day that would be quite helpful. But i’m sorry to say they didn’t both the guys started on the same day. Because they both work for the same company. It has the same number of employees. So, essentially make them live as well these two people are the same. But they’re not the same they are different people with humans.

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 perhaps one of them is large perhaps. One of them is a butcher the other one’s a Baker. So, you have another way of splitting the Data that is not really very 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 Primary Key Feature In Ms Access

Wherever your data is stored electronically you are given a unique reference, so that could be a national insurance number that could be an NHS number. It could be a policy number again i use the word number but it should be reference. Because that number can contain numbers and letters. So, what we need to do in our databases is to have some way of uniquely Identifying in this particular case our customers. And the easiest way to do that would be to give every new customer an ID. So, we need to go back into 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. Type auto number what auto number does is give 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 very easily allowing 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 the big button on the top primary key. It’s also on the right click primary key. Whichever one 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 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 though their data is exactly the same all the way along. A way of uniquely identifying which Gaetano Vaccaro. I am referring to it’s customer, one it’s customer two you’ll see then that. This says new on the next record i come down there. 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 Primary Key Feature in Ms Access

The Primary Key feature in Ms Access is important, Because i can’t type in that field it’s then given the next number. Because it’s giving it three so i’m gonna misses sally bell. She lives in the big house long lane small tune in the south. She started with us not on first of may but let’s go she started in first April. They have three employees and she’s live so don’t forget the space tab brings me down to the next row. And i’m ready for another new customer. So, that’s the primary key now 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 when that pop-up 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 Reg number. Products would they might have a special product number etc. If you don’t have an 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. On for each person every table needs a primary key. So, the moment we’ve only got one table but we will be adding other tables. Each of those tables will need their own primary key. They might turn out to be just auto numbers generated by access.

auto numbering In The Primary Key Feature In Ms Access 

But that’s great it just gives us that one way of saying that’s the record i want that one there. 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 record with the 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. It that’s the primary key vitally important.