Questions tagged [sql-insert]

The SQL INSERT statement allows you to insert a single or multiple rows into a table.

SQL INSERT statement adds one or more rows to a single table in a relational database.

The basic INSERT values syntax is:

INSERT INTO table [ (column1 [, column2, column3 ... ]) ]
VALUES (value1 [, value2, value3 ... ]);

The INSERT SELECT syntax is:

INSERT INTO table [ (column1 [, column2, column3 ... ]) ]
SELECT c1 [, c2, c3 ... ] FROM table

Reference

For questions regarding SQL INSERT statement use this tag instead of .

5071 questions
10
votes
1 answer

Postgres upsert using results from select

I'm trying to upsert with postgres using values from a select. It looks like: INSERT INTO foo (a, b, c) SELECT a_, b_, c_ -- hairy sql ON CONFLICT (...condition...) DO UPDATE SET "c"=??? On conflict, I want to use one of the values from my select…
RYS
  • 442
  • 6
  • 22
10
votes
4 answers

Why Bulk Import is faster than bunch of INSERTs?

I'm writing my graduate work about methods of importing data from a file to SQL Server table. I have created my own program and now I'm comparing it with some standard methods such as bcp, BULK INSERT, INSERT ... SELECT * FROM OPENROWSET(BULK...)…
zer_ik
  • 410
  • 1
  • 4
  • 14
10
votes
1 answer

Duplicating parent, child and grandchild records

I have a parent table that represents a document of-sorts, with each record in the table having n children records in a child table. Each child record can have n grandchild records. These records are in a published state. When the user wants to…
Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102
10
votes
3 answers

Android - SQLite ContentResolver insert/delete/update on UI Thread?

I have looked through many examples/tutorials of using SQLite in Android. Let's say you have an app that uses SQLite, ContentProvider, CursorLoader, a custom CursorAdapter. Now all major examples of this that I've found rely on a CursorLoader to…
Leo K
  • 808
  • 1
  • 9
  • 24
9
votes
2 answers

Inserting values (generate_series) - how can I reuse/cycle the numbers, e.g, 1,2,3,1,2,3

I am using generate_series to insert values in a table. And generate_series insert values as specified in its range. For example: for the following query, SELECT i AS id, i AS age, i AS house_number INTO egg FROM generate_Series(1,6) AS i; the…
Rohita Khatiwada
  • 2,835
  • 9
  • 40
  • 52
9
votes
1 answer

How to get ON CONFLICT IGNORE working in sqlite

I'm trying to ignore inserts if a tag and url combo exist already: INSERT INTO tags(tag, url) VALUES (?, ?); ON CONFLICT(url, tag) IGNORE I have a UNIQUE INDEX on (tag, url) CREATE UNIQUE INDEX tag_url ON tags (tag, url) The…
chovy
  • 72,281
  • 52
  • 227
  • 295
9
votes
3 answers

MySQL: Why is DELETE more CPU intensive than INSERT?

I'm currently taking the course "Performance Evaluation" at university, and we're now doing an assignment where we are testing the CPU usage on a PHP and MySQL-database server. We use httperf to create custom traffic, and vmstat to track the server…
Trond
  • 91
  • 1
  • 2
9
votes
2 answers

Postgresql INSERT is asking for primary key value?

Running Postgres 9.6.6. I created a table as follows: create table person ( id serial primary key, name text, role integer references role (id), phonenumber text); When I try to insert data as follows: insert into person values ('This…
sigil
  • 9,370
  • 40
  • 119
  • 199
9
votes
4 answers

Select data from db table 1 and insert it into another db table 2 in php

I have two different Databases, names: dbtest: Table 1 dbtest2: Table 2 I want to select all the data and new entries from dbtest Table 1 to dbtest2 Table 2. I have tried this $sqlfin = "INSERT INTO dbtest2.Table2 SELECT * FROM…
Ashley
  • 141
  • 1
  • 7
9
votes
1 answer

MySQL error #167 - Out of range value for column even when it is autoincremented

I have a field (called ID) that is defined as: smallint(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32768 I have a query as follows (simplified): INSERT INTO delivery (`ConsigneeName`, `ConsigneePhone`) VALUES ('John Doe', '9999999999') And have…
Chiwda
  • 1,233
  • 7
  • 30
  • 52
9
votes
4 answers

What is an efficient way to handle inserts of unique "immutable" entities by multiple producers with optimistic concurrency approach?

Assume a system with multiple concurrent producers that each strives to persist some graph of objects with the following common entities uniquely identifiable by their names: CREATE TABLE CommonEntityGroup( Id INT NOT NULL IDENTITY(1, 1) PRIMARY…
9
votes
2 answers

How to insert custom values with INSERT INTO + SELECT FROM?

i would like to insert custom values along with table columns when i perform INSERT INTO ...SELECT FROM ... WHERE clause INSERT INTO RoleMappingEmployee_Delete_History ( RoleMappingEmployeeKey, SrKey, RoleKey, SubmittedDate, …
coolstoner
  • 719
  • 2
  • 9
  • 20
9
votes
7 answers

Insert Multiple Rows SQL Teradata

I am creating a volatile table and trying to insert rows to the table. I can upload one row like below... create volatile table Example ( ProductID VARCHAR(15), Price DECIMAL (15,2) ) on commit preserve rows; et; INSERT INTO…
Bocean
  • 103
  • 1
  • 2
  • 7
9
votes
4 answers

Inserting large number of records without locking the table

I am trying to insert 1,500,000 records into a table. Am facing table lock issues during the insertion. So I came up with the below batch insert. DECLARE @BatchSize INT = 50000 WHILE 1 = 1 BEGIN INSERT INTO [dbo].[Destination] …
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
9
votes
2 answers

Insert boolean value into sqlite table

I created a table MYTABLE CREATE TABLE "MYTABLE" ( "surname" VARCHAR, "name" VARCHAR, "id" INTEGER PRIMARY KEY NOT NULL , "flag" BOOL); when I insert a record with: INSERT INTO "MYTABLE" VALUES ("Super","Mario","94",…
yaylitzis
  • 5,354
  • 17
  • 62
  • 107