MySQL Insert Into

Data can be inserted in to an existing database table with an INSERT INTO query that first specified the table name. The SQL VALUES  keyword then specifies the actual data to be inserted as comma-separated list with in parentheses, like this :

INSERT INTO table-name VALUES(value, value);
Each INSERT INTO query inserts just one row into the database table. A data value must be specified for each column – and in the corresponding order. The data to inserted must also match the data type in each column’s definition or an error will be generated.The NULL  keyword can be specified to leave a field empty if that column’s definition allow NULLvalues.

The INSERT INTO query can be improved by adding a “column list” to explicitly specify the table column into which each value should be inserted. This changes the syntax of the INSERT INTO query like this :

INSERT INTO table-name(column-name,column-name,column-name)

When the INSERT INTO query contains a column list the MySQL Server matches each value to the specified column in the order in which they are listed – the value listed will be matched to the column listed first, the value listed second will be matched to the column listed second and so on. The number listed values must match the number of listed columns, but the columns need to be listed in the order in which they appear in the database table.

Any text values to be inserted into a database must be enclosed with in quotation marks.
Ex :
name VARCHAR(100),
designation VARCHAR(100),
salary decimal(6,2)
// Query for data insertion
INSERT INTO tblemployees(name,designation,salary)
VALUES("Anuj kumar","software Developer","60000.00"),
("John Doe","Accountant","80500.25"),
("Garima","HR Executive","40134.65");

Recommended Tutorials for you


Anuj kumar

This is Anuj Kumar. I’m a professional web developer with 5+ years of experience. I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials. .

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.

Check Also
Back to top button