Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
I have a one-many number of records that need to be entered into a table.

What can be the best way to do this in a query?

Can I just make a loop and insert one record per iteration? Or is there any better way?

1 Answer

0 votes
by (12.7k points)
edited by

INSERT statements that use VALUES syntax can insert multiple rows into the table. 

To do that, include the multiple lists of column values, each enclosed within parenthesis and separated by commas. 

Refer MySQL manual for more info.

Example:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

If you want to learn more about SQL, the best online SQL courses by Intellipaat that offers instructor-led training, certification, and job assistance.

Related questions

0 votes
1 answer
asked Dec 4, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 20, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...