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
€67.28
List Price:  €96.12
You save:  €28.84
£55.93
List Price:  £79.91
You save:  £23.97
CA$98.01
List Price:  CA$140.02
You save:  CA$42.01
A$107.87
List Price:  A$154.11
You save:  A$46.23
S$94.42
List Price:  S$134.90
You save:  S$40.47
HK$544.78
List Price:  HK$778.29
You save:  HK$233.51
CHF 62.22
List Price:  CHF 88.89
You save:  CHF 26.67
NOK kr779.46
List Price:  NOK kr1,113.56
You save:  NOK kr334.10
DKK kr501.79
List Price:  DKK kr716.88
You save:  DKK kr215.08
NZ$119.98
List Price:  NZ$171.41
You save:  NZ$51.43
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,402.58
List Price:  ৳12,004.20
You save:  ৳3,601.62
₹5,911.93
List Price:  ₹8,445.97
You save:  ₹2,534.04
RM312.68
List Price:  RM446.70
You save:  RM134.02
₦118,358.68
List Price:  ₦169,091.08
You save:  ₦50,732.40
₨19,451.98
List Price:  ₨27,789.74
You save:  ₨8,337.75
฿2,421.30
List Price:  ฿3,459.15
You save:  ฿1,037.85
₺2,419.75
List Price:  ₺3,456.94
You save:  ₺1,037.18
B$406.81
List Price:  B$581.19
You save:  B$174.37
R1,266.21
List Price:  R1,808.95
You save:  R542.74
Лв131.43
List Price:  Лв187.77
You save:  Лв56.33
₩98,455.31
List Price:  ₩140,656.47
You save:  ₩42,201.16
₪260.61
List Price:  ₪372.31
You save:  ₪111.70
₱4,125.84
List Price:  ₱5,894.31
You save:  ₱1,768.47
¥10,813.84
List Price:  ¥15,449
You save:  ¥4,635.16
MX$1,432.62
List Price:  MX$2,046.69
You save:  MX$614.07
QR256.35
List Price:  QR366.23
You save:  QR109.88
P959.91
List Price:  P1,371.36
You save:  P411.45
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,476.67
List Price:  E£4,966.88
You save:  E£1,490.21
ብር8,762.26
List Price:  ብር12,518.05
You save:  ብር3,755.79
Kz63,877.12
List Price:  Kz91,256.94
You save:  Kz27,379.82
CLP$68,152.06
List Price:  CLP$97,364.26
You save:  CLP$29,212.20
CN¥507.37
List Price:  CN¥724.85
You save:  CN¥217.47
RD$4,236.71
List Price:  RD$6,052.70
You save:  RD$1,815.99
DA9,355.50
List Price:  DA13,365.57
You save:  DA4,010.07
FJ$159.32
List Price:  FJ$227.62
You save:  FJ$68.29
Q542.77
List Price:  Q775.43
You save:  Q232.65
GY$14,710.67
List Price:  GY$21,016.15
You save:  GY$6,305.47
ISK kr9,775.50
List Price:  ISK kr13,965.60
You save:  ISK kr4,190.10
DH703.21
List Price:  DH1,004.63
You save:  DH301.41
L1,276.61
List Price:  L1,823.81
You save:  L547.19
ден4,112.73
List Price:  ден5,875.58
You save:  ден1,762.85
MOP$563.70
List Price:  MOP$805.33
You save:  MOP$241.62
N$1,272.29
List Price:  N$1,817.64
You save:  N$545.34
C$2,573.53
List Price:  C$3,676.63
You save:  C$1,103.10
रु9,461.06
List Price:  रु13,516.38
You save:  रु4,055.32
S/267.08
List Price:  S/381.56
You save:  S/114.48
K283.05
List Price:  K404.37
You save:  K121.32
SAR262.80
List Price:  SAR375.44
You save:  SAR112.64
ZK1,938.90
List Price:  ZK2,769.98
You save:  ZK831.07
L334.76
List Price:  L478.25
You save:  L143.49
Kč1,707.89
List Price:  Kč2,439.96
You save:  Kč732.06
Ft27,663.65
List Price:  Ft39,521.19
You save:  Ft11,857.54
SEK kr779.03
List Price:  SEK kr1,112.95
You save:  SEK kr333.92
ARS$70,272.32
List Price:  ARS$100,393.34
You save:  ARS$30,121.01
Bs485.83
List Price:  Bs694.07
You save:  Bs208.24
COP$310,661.31
List Price:  COP$443,820.90
You save:  COP$133,159.58
₡35,743.76
List Price:  ₡51,064.70
You save:  ₡15,320.94
L1,776.85
List Price:  L2,538.46
You save:  L761.61
₲551,865.53
List Price:  ₲788,413.13
You save:  ₲236,547.59
$U2,996.30
List Price:  $U4,280.61
You save:  $U1,284.31
zł292.33
List Price:  zł417.63
You save:  zł125.30
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.