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
2
votes
2 answers

Insert OUTPUT Insert.id to another table in multiple values insert

Just for simplicity suppose I have two tables user table (id, email) user log table (id, date) whatever id gets inserted in user table, same id should be inserted in user_log table also else transaction should fail. How can I do this BEGIN…
Sami
  • 3,926
  • 1
  • 29
  • 42
2
votes
2 answers

Do not save empty rows

I have a table that contains a list of all products and before each one there is a field "number" in which the user will put the quantity then click on save. This code save all rows in data base using mutiple-insert but I want that if quantite is…
hous
  • 174
  • 4
  • 11
2
votes
1 answer

insert update multiple rows mysql

I need to add multiple records to a mysql database. I tried with multiple queries and its working fine, but not efficient. So I tried it with just one query like below, INSERT INTO data (block, length, width, rows) VALUES ("BlockA", "200", "10",…
Irawana
  • 269
  • 3
  • 6
  • 14
1
vote
1 answer

Change input radio value in multiple row update form

I can't changed the value in a row inside of my DB, when I select another radio different of the checked in the update form... always returns the previous state... How can I make it works? Here are the captures: How the radio is checked The…
user3236149
  • 167
  • 4
  • 16
1
vote
2 answers

PotgresSQL INSERT INTO SELECT CASE problem

I have the the following query and I'd like to insert any number of rows from the sub queries. Of course I'm getting an error SQL Error [21000]: ERROR: more than one row returned by a sub query used as an expression since some of the sub queries…
1
vote
1 answer

Oracle/ multiple inserts without Loops

I have the following table table_1 which contains thousands of rows: Num_replication object_name -------------------------------- 4 obj_1 8 obj_2 12 obj_3 for each of one of these rows, I…
user123
  • 387
  • 1
  • 4
  • 13
1
vote
1 answer

PHP MySQL InnoDB Multiple Inserts to Different Tables Using Transactions Failed

I have been studying transactions and from what I understand, my multiple insert statement should work. I'm using InnoDB engine. Both insert statements below work and correctly enters the data into the respective tables, but only if I have one of…
Mike
  • 607
  • 8
  • 30
1
vote
0 answers

Batch Request in Https Post C#

I have written C# Job to read from IIS line by line and create the JSON and post the data to DB.The Job is reading 45K lines and inserts operations are very slow. I enabled the parallel programming in job but still the performance was very slow. It…
1
vote
4 answers

insert multiple same input fields php

Good day.
Oween
  • 13
  • 6
1
vote
1 answer

Add new contacts (36 items)

im trying to add new contacts to the phone but he does only the first 12 items. i want to try all current 36 items and maybe more add to the phone contacts. while ((line = bufferedReader.readLine()) != null) { …
1
vote
3 answers

Adding SELECT COUNT(*) subclause trashes performance in SQL Server

I'm building a query and the latest step involved adding a SELECT COUNT(*) FROM [modification] sub-clause to allow me to detect the last row of the query, but it destroys the performance: SELECT CONCAT( IIF(row_number() OVER (ORDER BY…
Adam
  • 5,215
  • 5
  • 51
  • 90
1
vote
0 answers

Primary key (Auto_Inc) and Unique key index causing deadlock while attempting multiple inserts

I am facing a MySQL Transaction Deadlock on a slow test server. I am not much good with SQL but i have tried re-executing the query in case of Deadlock but the result remains the same. I have two indexes on the table - "Primary key index" (Single…
1
vote
1 answer

insert each object in the list, update it if it exists already

I still have problems with insert/update of multiple items. The thing is I have a list of N items, each of which (item) I want to insert. But if an item with the same unique key already exists, I want to have it updated instead. (An item contains a…
dexter
  • 738
  • 2
  • 10
  • 19
1
vote
1 answer

insert multiple values using prepared statement using loop java

I'm trying to insert multiple values in a mysql database using the iterative (for) but it always insert the first line and stops. String rq="insert into seance values (?, ?, ?,?,?,?);"; try (Connection cnx = Connecteur1.getConnection();…
zbart3i
  • 11
  • 6
1
vote
2 answers

How to change one-to-one relationship to one-to-many relationship in MySQL?

I currently have a user's table which contains a one-to-one relationship for Youtube OAuth tokens. However, I now want to support multiple video sites and want to break this into a one-to-many relationship. I have setup the new tables: tokens -…
Matt McCormick
  • 13,041
  • 22
  • 75
  • 83