Don't Afraid of Source Code

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");
Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy