7 hours 36 minutes
I welcome the model to databases. This is less than 1.3, the one the one relationship and the previous lesson. We discussed how database tables are similar to spread sheets in concept.
within that previous example,
I had a good sample of a 1 to 1 relationship.
So I opened up the two spreadsheets that
did a good job of showing that type of relationship. So we have the employee spreadsheet on the state's fresh sheet,
and if we take a look at the employees spreadsheet, we can see that an employee can have one state
and that one state will tie to something on the state table. For example, Kit Parker has a state idea of two,
and two is California,
while John Smith has a state idea of one and one is Arizona.
That's a good 1 to 1 relationship.
there's a service I use, and unfortunately, it's not a free service, but it doesn't. Excellent job is allowing to diagram databases and then create that DOT database based on that diagram, and that's Verte Bello.
If you do have a student account, you can sign up for their free student account. Otherwise they have a free trial with a monthly service feet.
But within Verte Bellow, I have diagrammed these spreadsheets into two tables with that relationship.
So if I click on the employees table, we'll see the column. Names of I. D first name, last name State just like that occurred on the spreadsheet.
In addition to that, we'll see how those fields are defined with respect to data type.
For example, the I D is an ent or energy, which means it must be a number
first name and last name or both. Defined is Var char 30 which means it could be text up to 30 characters long.
And we can see that state is defined as an imager, which is a clue that there's probably a state table
if you didn't happen to have the diagram in front of you.
In addition, we could see the idea is also marked. Is the primary Key or P K for short?
Now again, if you click on the state table, we'll see the name of state.
We'll see the columns with their names of I D name code
with their types,
with idea being that of an ent or energy er and mark with P k or Primary key
name Having a bar chart 30 which again means text that could be 30 characters long
and a column of code, which is a bar chart, too, which means it's text that could be two characters long.
And this line in the center represents the relationship.
And if you click on that, we'll see that we have a carnality of 1 to 1. We could change that in. The diagram would change to reflect what we pick.
So that's what the one too many
relationship looks like. But we're gonna change it back to 1 to 1, because that's over working with. That's what we're talking about.
And again we could see that we define the primary
from the state
And the foreign is on the employees
and it's mandatory,
which means that you can't insert data that violates this relationship.
So the nice thing about Verte Bello is we can actually click the sequel button.
We can click the generate button. After that
click, save or download,
we can click open.
Now we're gonna get rid of this bottom. This is noise. If you were using this, you won't see this. This is from something I was doing earlier.
So the nice thing about this is we can actually take this and copy it
into D Beaver.
we need to open D beaver, and you should see the connection that you established in a previous lesson.
Expand the databases. We're gonna make a new database.
I'm gonna create a new database. We're just gonna give it a simple name like test, but you can call it whatever you like.
And we're going to right? Click that new database. We're gonna set it as the active database.
Then we're going to click the sequel editor
and Click New sequel editor.
We're gonna pace that code in there.
We're gonna move the cursor to the first statement because D Beaver will attempt to run
the query based on where your cursor is.
So we've taken that Verbillo code, which generates the diagram we just defined.
And to run that whole statement in De Beber, you need to select the button that says Execute sequel script.
Have you tried to click just the play button? It will only execute your top statement.
So let's go ahead and execute the entire sequel script,
and we're seeing that it did three Curries queries. Which makes sense because one,
and we could see the If we take a quick look at the create statement, we'll see what it did was say that it created a table named employees.
We can see that there was, for example, an i. D.
There was an imager rent, and it's not allowed to be no, which means it has to be filled in.
Well, let's not worry about that in too much detail right now. Let's see what was created
on their way there. We have our two tables, employees and the state.
And if we clicked on employees and we clicked,
de Beaver will show us that relationship we just defined,
which is, Ah, very neat feature. So if you're working with my single database that has had the four keys to find, you can very quickly
look at the tables and see the type of relationships you are working with, so you can better query that database. Now. It is common,
more common than you'd probably like to think for
designers to not define the relationship
and what that means is they didn't run this.
They didn't. They didn't add the foreign key.
And then what they do is buy convention. They respect that relationship,
and the issue there is that it's not clearly defined what the relationship is. You kind of have to assume what it is and do a few checks to check your assumption. And also it can lead to some weird data entries that don't follow the relationship that someone might have actually left in the database as noise.
So this has been the 1 to 1 relationship, and the next tutorial will go over the one too many relationship.
And then after that, we'll go through a couple more relationship types, and then we'll tie it all together.
I hope you enjoy this lesson, and I hope to see you in the next lesson. Thank you for your time.
Penetration Testing and Ethical Hacking
The Penetration Testing and Ethical Hacking course prepares students for certifications, like CEH. This course ...
7 CEU/CPE Hours Available
Certificate of Completion Offered
This free course introduces the student to intermediate concepts found in the implementation and application ...
10 CEU/CPE Hours Available
Certificate of Completion Offered