Questions tagged [multiple-insert]

Use this tag for questions about inserting multiple rows in a single statement into an SQL database.

Multiple row inserts are a feature of many SQL databases. They're a feature of the SQL-92 standard.

The most common syntax for multiple row inserts is similar to a normal INSERT INTO statement, but with multiple value groups separated by comma's

INSERT INTO MyTable(Value1, Value2)
VALUES 
    ('Value1Row1', 'Value2Row1'), 
    ('Value1Row2', 'Value2Row2'),
    ('Value1Row3', 'Value2Row3')

Alternatively, multiple row inserts can be achieved by using an INSERT INTO ... SELECT statement and UNION queries in many RDBMS.

For more information, see Wikipedia on multi-row inserts.

81 questions
106
votes
8 answers

MySQL - how many rows can I insert in one single INSERT statement?

Does it depend on the number of values sets? Does it depend on the number of bytes in the INSERT statement?
Luistar15
  • 1,699
  • 3
  • 14
  • 16
50
votes
11 answers

How should I multiple insert multiple records?

I have a class named Entry declared like this: class Entry{ string Id {get;set;} string Name {get;set;} } and then a method that will accept multiple such Entry objects for insertion into the database using ADO.NET: static void…
bottlenecked
  • 2,079
  • 2
  • 21
  • 32
17
votes
3 answers

While inserting multiple rows what does the statement 'select 1 from dual' do?

While inserting multiple rows into a table using the following style : insert all into ghazal_current (GhazalName,Rating) values('Ajab Apna Haal Hota Jo Visaal-e-Yaar Hota',5) into ghazal_current (GhazalName,Rating) values('Apne Hothon Par Sajana…
Y.E.P
  • 1,187
  • 6
  • 20
  • 40
12
votes
5 answers

Inserting multiple rows with sequence in Oracle

This is the query i have used for insert multiple rows in oracle database. But when am using sequence within it it raises error as ORA-00001: unique constraint. How to do it. INSERT ALL INTO POSTAL_CODE( postal_code,desc) …
user5122076
10
votes
1 answer

MySQL's AUTO_INCREMENT behavior in a multiple row insert

I think the answer to my question is obvious but since I could not find any documentation to support it, I thought it's worth asking. At least for the record. As we all know AUTO_INCREMENT fields are incremented each time an INSERT statement is…
Mehran
  • 15,593
  • 27
  • 122
  • 221
10
votes
2 answers

SQL Server: multiple INSERT with MERGE

What is the method to do multi insert of values into SQL Server database? Usually in MySQL I use queries like: INSERT INTO table (column1, column2) VALUES(value1, value2), (value3, value4) ON DUPLICATE KEY UPDATE column2 = VALUES(value2); Is there…
4
votes
1 answer

multiple value inserts to Postgres using Tokio-postgres in Rust

I am using the below code to insert to a Postgres DB using tokio-postgres, is there any better option : let members = &[obj] //obj is a struct let mut params = Vec::<&(dyn ToSql + Sync)>::new(); let mut i = 1; let mut qry:String = "insert into…
M.Nair
  • 243
  • 2
  • 9
3
votes
2 answers

How postgresql multiple insert works when there is foreign key constraint in the table itself?

Let's say I have a schools table CREATE TABLE "public"."schools" ( "id" text NOT NULL, "ancestor_id" text, CONSTRAINT "schools_ancestor_id_fkey" FOREIGN KEY ("ancestor_id") REFERENCES "public"."schools"("id"), PRIMARY KEY…
AngryCat
  • 77
  • 7
3
votes
2 answers

PDO PHP - PDOException - Numeric value out of range: 1264 Out of range value for column 'customer_id' at row 1

I am trying to push a lot of rows (400-2500) into a table using a single 'multiple insert' query (PHP's PDO Driver). Now I get this error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22003]: Numeric value out of range:…
kgongonowdoe
  • 425
  • 3
  • 16
3
votes
1 answer

Laravel Eloquent -- Multiple record insertion in a table (with a column with unique constraint)

I have a table named 'categories' with uniqueness constraint on 'category_name' in my application, I want to inset multiple rows in 'categories'. Bad Solution: foreach($categories as $category) { Category::firstOrCreate(array('category_name' =>…
Muhammad Saud
  • 356
  • 3
  • 13
3
votes
1 answer

Laravel multiple insert into one table

I come here requesting some help with the logic of this case, and if possible, some help with the code as well. So here's the thing. Let's assume I have these two tables, which of course, have a One-Many relationship: *These aren't the real tables,…
arrigonfr
  • 742
  • 3
  • 12
  • 34
2
votes
2 answers

Codeigniter - multiple input with loop

I wanted to make the multiple inputs form with loop and the different value for each data I fill, it seems this code is working but it was only getting 1 data to 3 times with the same value. what I need is that I can make different value for each…
Happy Dog
  • 87
  • 1
  • 8
2
votes
2 answers

Insert multiple rows into two tables using autoincrement Mysql

I am trying to insert multiple rows into two tables connected by a foreign key that is autoincrement. I can't seem to find a good solution. Tables: eav_attribute_option option_id (PK,…
Domeglic
  • 181
  • 2
  • 11
2
votes
4 answers

Batch/Bulk SQL insert in Scrapy Pipelines [PostgreSQL]

I am using my own pipeline to store the scrapped items into a PostgreSQL Database, I made an expansion a few days ago and I store the data into a 3 Databases now. So, I want to make the pipeline which inserting the data to be called every 100 items…
Morad Edwar
  • 1,030
  • 2
  • 11
  • 27
2
votes
1 answer

Converting multiple SQL Insert statements into one single Insert statement

I have a problem where I am in the process of creating a database of teachers for my project. As a part of this process, I might have to use multiple "Insert" statements to enter all the various details about each teacher to create rows of data…
1
2 3 4 5 6