Insert Table Data MySQL Essential Training
In our previous lesson we’ve learned about how to create a table and view its structure by various MySQL CLI commands. Here we’re gonna teach you in this Insert Table Data MySQL Essential Training lesson, add a data into the table according to the fields we’ve defined as columns early.
To insert a data into a table, we have to login as a mysql user, use the database we want store the data. And finally confirm the table is exist we wants to insert a data. For more details about create a table please go back and see our previous lesson about create a table.
Before going to learn how to insert data into the table, we’ll see some basic shortcuts for MySQL Command Line Interface for your comforts.
CTRL + a -> Moves the prompt to beginning of the line.
CTRL + e -> Moves the prompt to end of the line.
ALT + a -> Moves the prompt one word before.
ALT + f -> Moves the prompt one word after.
CTRL + w -> Remove the previous word.
CTRL + u -> Removes the entire command.
CTRL + I -> It removes the previous commands and clear the screen.
ALT + u -> It changes the previous word to uppercase.
ALT + l -> It changes the previous word to lowercase.
ALT + _ -> It brings the last word we delete.
We hope you examining the commands in your upcoming lessons to make easy your command line interface experience. Lets begin to learn how to insert data into the table. As we said earlier if a sequence of data is added into a table then it’ll be called as row.
Each field the row is known as column, a row contains n number of rows depends on the project requirements. Here we see in our Insert Table Data MySQL Essential Training example we are gonna insert upto five columns according to our table we created in our previous lesson.
insert into table_name values(Col_value1, Col_value2,…, Col_value3);
The above shown is the very basic syntax for how to insert a row into the table. Insert is a keyword tells the MySQL, we are going to insert some data into the table. table_name is we’ve to mention the name of the table which we wants to insert in the list of tables. Values will gives the list of values to the query to execute.
mysql>insert into emp_details values(NULL, 'Androidhotspot', 'CEO', 9999988888, 'Seattle');
In Insert Table Data MySQL Essential Training lesson the above line we understand that we are insert a row into the table emp_details which is exist in the sample database. At first column we give the NULL value, because we declared it as auto_increment field. So we doesn’t need to give any values to that field. And the next column is given inside the single quotes, because they are the string values.
After give all the values in a order hit the enter. And your Output will be like this,
We can confirm whether the data is inserted properly or not by using the CLI commands. The Select command is briefly discussed in the upcoming lessons. But for the purpose we can use it here to check the row is insert or not.
mysql>select * from emp_details;
The above command will shows all the rows inserted in the table named emp_details. The output will be like this,
The above is the simple single row insert method for the beginner level programming. You’ve to take a lot more practices to make them as familiar as flow.
In this Insert Table Data MySQL Essential Training lesson we show you how to add more than one column at a time. Lets consider the following example, we can also take brief look on these concepts later lessons.
After the insert the row, we can check whether the data has been added or not like we did for our previous example.
We hope this lesson will teaches the basics of the insert table data mysql essential training. You’ve to exercise your own codes to get more familiar with these commands.