Insert Data into the Table with Workbench

MySQL Database Development Mastery Manipulating Tables and Data - CRUD Operations
9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.96
List Price:  €92.81
You save:  €27.84
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$106.02
List Price:  A$151.47
You save:  A$45.44
S$94.41
List Price:  S$134.88
You save:  S$40.47
HK$546.80
List Price:  HK$781.18
You save:  HK$234.37
CHF 63.34
List Price:  CHF 90.49
You save:  CHF 27.15
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.42
List Price:  NZ$166.33
You save:  NZ$49.90
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,416.31
List Price:  ₨27,738.77
You save:  ₨8,322.46
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$356.70
List Price:  B$509.60
You save:  B$152.89
R1,295.44
List Price:  R1,850.72
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪259.50
List Price:  ₪370.74
You save:  ₪111.23
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,712.31
List Price:  ¥15,303.96
You save:  ¥4,591.65
MX$1,187.89
List Price:  MX$1,697.07
You save:  MX$509.17
QR254.57
List Price:  QR363.69
You save:  QR109.12
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.64
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,764.23
List Price:  ISK kr13,949.49
You save:  ISK kr4,185.26
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.59
List Price:  ден5,712.52
You save:  ден1,713.92
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,305.79
List Price:  Ft36,152.68
You save:  Ft10,846.88
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
Already have an account? Log In

Transcript

Hey guys, in this video we will be looking at using the my SQL workbench interface to insert records into our data tables. So in our previous video, we would have looked at how to do it with a script, where we specify the database to be used. And then we wrote our keywords and our statements. And we looked at how we can insert one at a time versus many at the time. And you may be looking for a quicker and potentially easier way to do this without having to come in and write up a whole script. There are advantages to the script usage because then you can save the file and you can use it at a later date on maybe even another machine.

So that's the advantage to using the script file as its exportable. But then workbench also gives us a way to insert records directly without having to write a line of SQL code and to do that We can just hover on our table. And in this case, we've been interacting with the students table. So we can just hover on the students table. And then you'll see the three icons appearing. And the last one has like a lightning bolt on the table looking icon.

So we can click that. And we see that it executes some command that says select from the students. So you'll see that select query No, in a future lecture will break down that SELECT statement. But for know, that query will give you this result grid, which is what workbench uses to help you insert more records. So here, they're actually listing out all the records that we would have created. And you see that, like I said, In the previous video, for each record that was inserted, we get a unique ID.

All right, so it's calling things so that means the next one will be 10. And we see all of the data that we would have put in so if we wanted to create another student at this point, then we could actually just click in this row that has all values and just start filling in data. So I can see Williams and I can add a record for myself. I'm not going to tell you when I was born. All right, and I this was a typo, but I'm going to leave that because I wanted to see how my SQL handles erroneous records. So I'll just leave this one as No.

And then I press enter. So what happens is that when you press enter, it just goes on to the next one. So you can add as many as you need. All right, and then at the end of that process, you have to click Apply. And then apply is where we'll actually still generate code very similar to what we just wrote, which is just insert into and then you'll see that it kind of fully qualifies the database name where it says school db.com Students, because the reality is that if you don't have the use statement, then you can actually specify the database dot the table. And I kind of removes the need to have the use statements, because then you know exactly which table in which database is being targeted.

Alright. And then if we look at the rest of the code, it looks just like what we wrote all right values, and then it puts in the values including that invalid date. And then if I click Apply, then you'll see that it gets back with an error saying that an incorrect date value was tempted to be inserted. Alright, so so SQL, my SQL is actually doing its own validations on the data based on the data type that you specified. There is no 200 and first month, so that is just an error. So it knows that it should be year, month day, so of course it's going to validate before it attempts to put that in and that's it.

One of the principles of data integrity because data integrity speaks to having data that matches the needs and matches the standards set up by the designer of the database. All right, so I can just cancel that and make that part on. And I'll just add a few more rows. All right, so I've added a total of three rows with fairly consistent data standards or are in keeping with the data standards, not violating the integrity that we're looking for. And then I can just click Apply. And then you see that instead of doing the multiple insert is actually generating three different insert into statements.

So the thing with the multiple inserts is that if one of them fails, then the whole batch fields as opposed to doing one by one so that it will run this and then if this one fails, then it will probably just stop the execution of the script there, allow you to correct this one and then it will move on. So it That's the difference between it. So that's probably why they did it in three different statements to give each insertion command a fair chance as opposed to clumping them in one statement and feeling them all if one is bad, so we can just go ahead and click Apply. And we see here that there is still okay, I know what's happening. So this is actually a four digit year, and two digit month and then two digit day. So I have the 21st month there's no 21st one, I apologize.

So let me try that again. Apply. And I see my URL, I should not have put the value null, because null is kind of represented like this. So if I just leave it empty, then it will automatically know that this is a no. So let me try that again. Alright, so instead of having a lowercase low, then I'm going to have an upper case where no, which is actually a keyword.

And my skill is very particular about how it will enter it. So I'm just going to do that. Alright, so this is actually a good lesson. So if you want to leave something low, then it's best to just leave it. So my SQL represents it, because by me trying to type in the word know whether in lowercase or uppercase, or leaving it blank, we see that we're just getting some error here, and the operation is just going to fail. So I'm just going to remove this.

So to remove that, you can just click it, click the rule, and then right click and say delete rule and then it will remove it from that selection criteria. And then I'll just recreate it on here. Just so there's adequate preparation intuition. All right, and I'm not going to change that value that is there. And then I'm going to apply once more. And there we go, it was successfully executed.

And once we click finish, then we see that the number is incrementing. So you'll notice that it jumped all the way to 20. And that is because of all the failed attempts to insert, the ID was actually trying to auto increment each time. And then it just kind of associated any failure with a bad idea that's already used. So it just went to the next set of ID. So all the times I feel just No, he would have gone up by 10 1112 1313 1415, and 16 1718.

All of those failed. And until now it's at 2021 22 because now it was successful. And the next available number at the time was 20. So that's While these IDs would have jumped, so that is some behavior that you can expect from auto incrementing primary keys, and do remember that the next record will always get the next number and that is available as it comes up. So from this view, you actually have the option to insert records like this in a grid view, we can change records data right here, as long as you click apply at the end. You can also change the view, you can change the form editor that allows you to see it in a nice form view or fields under type so you can see all of the dates on the fields.

And you can also see query stats within this is for later when we start getting into some of the fun querying stuff in our select section, so essentially that's how you would go about inserting records into your table using My SQL workbench interface

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.