Transcript for:
Access Relationships and Data Integrity

Okay, welcome back. Now, I'm not actually going to enter all the data that's in this table. If you want to do that, in fact, that would be excellent idea to kind of get some practice on entering data on the command line for Microsoft Access. All of the data is in the book. You just kind of have to follow along. So, I'm going to assume you've done that step and I'm going to move on to building the relationship between these guys. So, I probably need to check to see if I actually have primary keys. Okay. Okay. Well, you know, hey, how can I tell whether or not I have a primary key or not? Is there is there some visual way? H I could do rightclick and go to the design view and see. Okay, I got a primary key there. Let me pop open to there. Yep, I got a primary key there. Yep, I got a primary. But I don't see any of the foreign keys. The foreign keys are done through a different process. It you use database tools and go to relationships. That's exactly what we're going to do. So, I'm going to go to database tools and click on the relationship guy. And then it says, do I want to add the selected table? I want to add them all. So, I'm just going to I'm going to hold the control key down and click on all three of these guys and hit add. Boink. Okay, cool. So, now I'm going to do some trickery. I'm just going to drag and drop things that kind of match. I know that this class number matches that class number, and that student number matches that student number. So, I'm actually going to grab this guy and like drag and drop him onto that class number. It's going to come up and say, "Hey, is this what you had in mind?" Because, you know, you could have dragged and dropped it on the wrong thing. And I'm going to say, "Yeah." And then I'm going to grab this student number and drag it onto student number. And it says, "Hey, you want the student number in student to be related to the student number in grades?" I go, "Yeah." So, what we've done is we've now created the relationships. So this is how you get to see the relationships. Okay. Kind of cool. Okay. So dragging them across. One of the things that was on that screen was enforce referential integrity. I typically do have that turned on when I'm building relationships. But you know, so I click on this guy, maybe do a right click and bring up edit. And I say, "Oh yeah, I really wanted to enforce referential integrity." What that means is every time I adds a uh a grade, it's going to check to see, wait, does that student actually exist? It's it's a matter of protection. It's one of the rules that the database can do for us. So, I'm going to do that. And I'm going to go here and do the exact same thing on this guy. Edit the relationship. I'm going to say enforce and hit the button. And then I'm going to hit close to say, "Hey, you want to save this thing?" And I go, "Yeah, I certainly do." Okay. So, what was the point of having this relationship? Okay, let me just give you an example. I'm going to go here to grade and I'm going to enter student number uh one and go to class number 10 and he made a I don't know a 95.6 and I'm going to move past it and it's going to come up and say I'm sorry you can't do that because you don't have a student number one. So, reference integity is to keep you straight. Okay? It's to kind of keep you on you can't enter garbage into your database. It also means that you have to enter the data in the correct order. In other words, I don't start with entering grade table. That won't work. You need to be filling in the class table and then the student table and then the grade table. Okay. Remember I was talking about how I have a pencil here and I can't move off of it because it's it's wrong. And so to back up, I'm going to hit the escape key. All right, makes sense. So escape key is the way you get out of it. How to to not commit a change. Like the I had the pencil meaning there was things that needed to be ch saved, but I didn't want to save it because it wouldn't allow me. So the escape key was the way to do that. Okay, so one more time. Um why do we do the relationship thing before? You know, we had a choice. We could fill all the data in and then do the relationships or we could do the relationships and fill the data. Now, it's a matter of where do you get the error message? If we had filled in all the the data first, which is the way I think the textbook is set up, and then did the relationship, it's going to come back and say you can't build this relationship because something is wrong. It's not necessarily going to tell you exactly where the problem is. Now, if you did the other way around, you did the relationships first and then started adding the data. As soon as you got to that row, it'd say, "Stop. You You made a typo. there is no there is no student 42. So one one type of error message is hey something went wrong you get to figure it out and the other is you can't do this insert because this data right here is the problem. So I kind of like doing the relationships first. Okay. On page uh 33 they talk about creating and running queries. I'm going to let you do that on your own. I don't think that's something I need to be able to do. So this is all that's in the book there. You just need to follow along in the book. Okay, this is a very short uh uh chapter and I'll see you guys again in the next chapter.