All right. Welcome back to Mali, Joe. Three sequel programming. This is less than one sequel Statements were in Sub Lesson 1.5 The insert statement. Now for this lesson, we're going to focus on a smaller table, and the reason we're going to do that is just so that we do not have to deal with a large number of columns. Of course,
you could take this insert statement, apply it to a larger table, and you would just need to include the additional columns that you had to account for. Now, the table we're focusing on is this one e p employees position cavey extension,
so you can find that by just filtering it down on the top
and then finding it and given it a double click.
Let's go ahead and take a look at the diagram
we could see. It is indeed a smaller table with a total of seven fields.
Now this table is used by Aqim Attica to facilitate customization. Sze
Ah, if you had a company with very unique requirements that they couldn't account for in the core product, they could have a programmer create custom fields that would allow the consumer to store data in those custom fields
with that data in a way that they really couldn't plan for
in their core product. And the reason for that is just
you run into a bunch of different company types that just have different work flows. They store different data, they're interested in different data, and the only way to really facilitate that is to leave room for customization.
we're not focusing on that. We're focusing on how to do an insert statement, so let's get to it.
So if we left click on that table name, we right Click
de Beaver has an excellent feature called Generate Sequel,
and we will go to that feature and we will click the insert statement
and this will pop up a box that shows you what the insert statement for that table looks like. And we can see that this statement is similar to the update and select statement and that we have
and sir, into table name.
These column names these values, so it's table name of columns values.
So we're gonna go ahead and copy that
we're going to close it,
and we're going to open up a new sequel editor.
Let's go ahead and paste that in to that sequel editor.
Now this has the full name, which is database name, table name.
or we should have the ACU Matic, a database said as the active database. So we actually don't need that doesn't matter if it's there or not. If you don't have it, said, is the active that evasive? You will need it there so that the statement can run correctly.
So let's go ahead and insert some data. Let's just say company I d. 99 record I d.
Ah, value in America will just say 123
value date. Let's do today
might be a different day for you. We'll probably be a different for you.
string in Texas. Very similar ideas. It's probable that a programmer could decide to leave one blank or not, depending if he wanted to save space. But a string in texts are very similar in concept,
so we filled this in. Let's go ahead and run the statement
and it says it updated one row
and its reporting that it was successful.
So let's go take a quick look
by giving that table a double click
and clicking on the data.
Okay, so there we go. There's Thedot A. We just applied, we correctly inserted into the table,
and it worked just fine.
Now something keep in mind when you are inserting or updating data, select snot is
Ah, what's the word? I would say, um, dangerous
within certain update
if especially if you're going directly into the database, you have to be very confident
that you are applying the correct changes.
In fact, you normally will want to be sure to back up any data that you're changing so that you can revert back if necessary.
Um, and the reason is is that when you're interacting with the database, there's
if there's no constraints, there's literally no rules on what you can do to the database. So,
as a quick example, I put company I D 99. That company does not exist in this database, so it is a broken relationship. It's this record that sitting out here in this table that doesn't relate to anything, and this would be considered bad
just because Dada they insert into a database. You want those
relationships to carry throughout the database so that things make logical sense and when these applications get set up, their set up in ways that prevent,
um, things like this from happening. For example, if you were going to insert a record from the front of an application, the front and application would on Lee let you select from a list of companies that exist. And if you wanted to use company I D 99 you would have to go create a company 99 before you used it.
That isn't the case here. We could just insert
anything we want and the database will accept it. So that's just a
small thing to keep in mind
when working with databases, working with inserts and updates statements.
So outside of that, you can see the insert statement was pretty easy. You just insert into the table, name
the column names, and then the values you want. Insert into those columns now. There were no constraints on this table if there had been.
We can see that in the diagram that this table has no constraints tying it to any other table. If there had been a constraint,
whatever constraint there was in that table
might have required it to exist. For example, an easy constraint would be a company table where Company 99 would have to exist in the company table before we inserted into
the employees of position table. But that constraint doesn't exist. So we were able to insert company
So that brings this lesson too close. I hope you got your insert statement. I hope you enjoyed it. And I will see you in the next lesson. Thank you.