

Still, at some point in your career as a MySQL DBA, you might need to look into INSERT statements and import rather large amounts of data (data comprised of 100,000 rows or more) into your database instances. Inserting data into your MySQL instances gets you pretty far. The error is pretty self-explanatory: the number_column column accepts numbers and not text values: we have fed it something else, and MySQL did not like it. #1366 - Incorrect integer value: 'Demo' for column 'number_column' at row 1 Where number_column is of type INT, MySQL would not execute the query and instead would return an error like so: What that means is that if, for example, we would run a query like so: INSERT INTO arctype (number_column) values ('Demo') However, the INSERT query also comes with some caveats: the data inserted into the table must conform with the data type of the column set in the table. It would flawlessly execute too! The upside of this is that we also reduce calls made to the database itself. VALUES ('Demo Data', 'Demo 2'),('Demo Data Again', 'Data123'),('Data here', 'Data here too') It would work just the same as an earlier example.Īlso, we could make use of inserting multiple rows at once, a query like so: INSERT INTO arctype (demo_1, demo_2) In this case, a value of Demo would be inserted into a column called column and a value of Demo 2 would be inserted into column_2.Īlso, keep in mind that when we're adding values for every column in the table, we don't need to specify columns: INSERT INTO arctype VALUES ('Demo', Demo 2') We can also run INSERT statements like so: INSERT INTO arctype (column, column_2) VALUES ('Demo', 'Demo 2') 'Demo Data' inserts a row with the text 'Demo Data' inside a column column_1.Īfter we would run such a SQL statement, some demo data will be added to our table.VALUES specifies that values will be set after this parameter.column_1 refers to the column name of the column to which we want to insert data.demo_table is the name of the table into which we want to insert the data.The INSERT INTO statement tells MySQL we want to INSERT data instead of SELECTing, deleting, or updating it.INSERT INTO demo_table (column_1) VALUES ('Demo Data') Īs you can see, the statement is comprised of a few parts:

In its most basic form, the statement looks like so:

To begin with, the INSERT statement, as its name suggests allows us to insert data into a table. However, when we are facing those two choices, we probably are not sure which one of them is better – that's what we are looking into today. Such a statement might be helpful if we find ourselves working with a lot of data inside our database instances. However, MySQL also has another way that dumps can be imported – LOAD DATA INFILE.

One of those – the INSERT INTO statement – could be considered a standard way to do so. XAMPP uses MariaDB instead of MySQL as its database solution.If you have been working with MySQL for a while, you probably already know that MySQL offers multiple methods for importing data.
MYSQL INSERT INTO CODE
If you’re using XAMPP, the following code does not apply and you may skip this section of the lesson. When we run the example above, it adds three more users to our table.
