MySQL INSERT INTO Statement
The MySQL INSERT INTO statement permit you to insert one or more rows into a database table.
Note: Make sure the order of the values is in the same order as the columns in the table.
MySQL INSERT INTO Syntax
To inserd the record into the table, use the following syntax:
Syntax
INSERT INTO table_name ( col1, col2,...colN )
VALUES ( val1, val2,...valN );
MySQL INSERT INTO Syntax for all fields
To insert the record for all the fields into the table, use the following syntax:
Syntax
INSERT INTO table_name VALUES ( val1, val2,...valN );
Note: You need to have an INSERT privilege to use the INSERT statement..
MySQL INSERT INTO example for all fields
The following MySQL statement to store all the field values, either specify all field name or don't specify any field name.
Example
INSERT INTO tblCustomerLoan
VALUES ('Mahesh', 'Malhotra','12-13-2/2A, new Delhi','123456789012','ABCDE3333G',1234567890);
OR
INSERT INTO tblCustomerLoan (firstName, lastName, address, aadharNo,panNo,cellNo)
VALUES ('Mahesh', 'Malhotra','12-13-2/2A, new Delhi','123456789012','ABCDE3333G',1234567890);
Note:
In the above example, we inserted new record into the table called "tblCustomerLoan".
You can use MySQL Command Line Client to insert record into the table. It will look like this:
Show INSERTED RECORD
You can check database table for newly inserted record using the following query:
Example
SELECT * FROM tblCustomerLoan;
You can use MySQL Command Line Client to show inserted record from table. It will look like this:
MySQL INSERT INTO Syntax for partial fields
It is mandatory to specify field names. To insert the partial fields into the table, use the following syntax:
Syntax
INSERT INTO table_name ( col2, col3, col4)
VALUES ( val2, val3, val4 );
MySQL INSERT INTO example for partial fields
The following MySQL statement to store partial fields value into the table.
Example
INSERT INTO tblCustomerLoan (address, aadharNo,panNo,cellNo)
VALUES ('12-13-2/2A, new Delhi','123456789012','ABCDE3333G',1234567890);
Note:
In the above example, we inserted partial record into the table called "tblCustomerLoan".
You can use MySQL Command Line Client to insert partial record into the table. It will look like this:
Show INSERTED RECORD
You can check database table for newly inserted partial records using the following query:
Example
SELECT * FROM tblCustomerLoan;
You can use MySQL Command Line Client to show inserted partial records from table. It will look like this:
MySQL INSERT INTO Syntax to insert multiple records
To insert multiple records into the table, use the following syntax:
Syntax
INSERT INTO table_name ( col1, col1, col2)
VALUES ( val1, val2, val3 ),
( val1, val2, val3 ),
( val1, val2, val3 );
MySQL INSERT INTO example to insert multiple records
The following MySQL statement to store insert multiple records into the table.
Example
INSERT INTO tblCustomerLoan (address, aadharNo,panNo,cellNo)
VALUES ('12-13-2/2A, new Delhi','123456789012','ABCDE3333G',1234567890),
('A/12, Opp. PVR Cinema, Hyderabad','123456789012','WERTQ3333G',2888888980),
('A-12, Habsiguda, Hyderabad','123456789012','IOUYT3333G',2342323234);
Note:
In the above example, we inserted multiple records into the table called "tblCustomerLoan".
You can use MySQL Command Line Client to insert multiple records into the table. It will look like this:
Show INSERTED RECORD
You can check database table for newly inserted multiple records using the following query:
Example
SELECT * FROM tblCustomerLoan;
You can use MySQL Command Line Client to show inserted multiple records from table. It will look like this: