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 :
1 |
INSERT INTO table-name VALUES(value, value); |
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 :
1 2 |
INSERT INTO table-name(column-name,column-name,column-name) VALUES(value,value,value); |
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 :
1 2 3 4 5 6 7 8 9 10 11 |
CREATE TABLE IF NOT EXISTS tblemployees( id INT AUTO_INCREMENT PRIMARY KEY, 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"); |