MySQL Tutorial – INSERT INTO Command

To add new record in the database, use the INSERT INTO command. Here is the syntax of INSERT INTO command:

INSERT into table_name (column1, column2….)
VALUES (value1, value2…);

Where: table_name is the name of the table where you want to insert new record; column1, column2 etc. are the name of the columns in the table and value1, value2 etc. are the values you want to insert in the table.

Note: The number of columns that you specify in INSERT INTO command should match the number of values you insert; otherwise you will get an error.We will add a new record in our table. Issue the following command:

INSERT INTO employee_record
(f_name, l_name, position, age, salary, email)
VALUES
(“Piolo”, “Pascual”, “Programmer”, 38, 25000, “piolopascual@yahoo.com”);

Note:

1. The name of our table is employee_record.

2. Values with quotes are string type (f_name, l_name, position, email) while (age, salary) are   integer type.

3. We have not inserted a record in id because we have defined it as auto_increment which means that the id field will increase by one every time we are going to insert a new record.

4. Once you have encoded the command correctly, it will display a success message.

Ex. Query OK, 1 row affected (0.00 sec)
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.