
| ID | Name | Age | Phone | Address | Email | You can verify the contents of the CustContactDetails table as shown below − INSERT INTO CustContactDetails (ID, Name, Age, Phone, Address, Email)

ID, CustomerName, CustomerAge, CustomrtPhone, DispatchAddress, Email Mysql> INSERT INTO CustContactDetails (ID, Name, Age, Phone, Address, Email) Here, we are trying to insert records from the SALES_DETAILS table to CustContactDetails table −

If we want another table with just the contact details of the customer create a table as −įollowing query insets records into the CustContactDetails table using the INSERT INTO SELECT statement. Mysql> insert into SALES_DETAILS values(1, 'Key-Board', 'Raja', DATE(''), Now, let’s insert 2 records into the above created table using the INSERT statement as − Suppose we have created a table that contains the sales details along with the contact details of the customers as shown below − INSERT INTO table_to (column1, column2, ……….) SELECT statement following is the syntax to do so − You can select desired column values from one table and insert them as a record into another table using the INSERT. | 6 | Speaker | Rahman | NULL | NULL | 5500 | NULL | If you retrieve the contents of the SALES table using the SELECT statement you can observe the inserted row as shown below Here, we are passing values only to the ProductName, CustomerName and Price columns (remaining values will be NULL) − Exampleįollowing query inserts a record into the SALES table using the INSERT…. If you insert record using this statement the values of other columns will be null. are the selected column names and the respective values. Where, table_name is the name of the table into which you need to insert the record and column_name1 = value1, column_name2 = value2. INSERT INTO table_name SET column_name1 = value1, column_name2 = value2. Following is the syntax of this statement − You can insert a record by setting values to selected columns using the INSERT…SET statement. | ID | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location | If you verify the contents of the Sales table using the SELECT statement you can observe the inserted records as shown below −

Now, let us insert 3 more records in Sales table. If you pass the values to the INSERT statement in the same order as in the table you can omit the column names − Insert into sales (ID, ProductName, CustomerName, DispatchDate, DeliveryTime, Price, Location) values(1, 'Key-Board', 'Raja', DATE(''), TIME('11:00:00'), 7000, 'Hyderabad') ExampleĪssume we have created a table with name Sales in MySQL database using CREATE TABLE statement as shown belowįollowing query inserts a row in the above created table −

Where, table_name is the name of the table into which you need to insert data, (column1, column2, lumnN) are the names of the columns and (value1, value2, value3.valueN) are the values in the record. INSERT INTO table_name (column1, column2, lumnN) Syntaxįollowing is the syntax of the INSERT statement of MySQL. In this, you need to specify the name of the table, column names, and values (in the same order as column names). You can add new rows to an existing table of MySQL using the INSERT statement.
