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
7
votes
1 answer

Transaction Deadlocks on SQL Server Insert with EF Core

I'm trying to do a large number of individual inserts containing a large amount of data quickly using Entity Framework Core. I'm inserting data into several related tables and occasionally get a SqlException with the following message; Transaction…
7
votes
2 answers

Android Room. Which method of insertion will be faster?

I am using Room as an abstraction layer over SQLite. After reading this page I found out that we can insert multiple objects at the same time. Currently I use a For loop to insert objects, i.e one object in each For loop iteration. The two ways of…
7
votes
1 answer

Postgresql parallel bulk INSERT with worker don't parallelize

My scenario: 10 worker Database has set 100 max connections Every worker has its own DB connection (max. 10 connections) Every worker starts a transaction (BEGIN; COMMIT;) Every worker inserts data in the same table with bulk insert inside the…
7
votes
1 answer

How can I perform a bulk insert using sqlite3 in node.js?

I need to insert 10 rows to a sqlite3 table, and once the insertions are done, pass the 10 id's of the new rows to a callback function in an array. My problem is that I can't figure out how to make a prepared statement perform multiple inserts at…
John Palmer
  • 101
  • 1
  • 5
7
votes
1 answer

Inserting datetime with milliseconds into SQL Server table issue

I came across something that I think has to do with time resolution in SQL. Here's an example I've used: CREATE TABLE #table ( DTstamp DATETIME NOT NULL ) INSERT INTO #table VALUES ('1 apr 2016 15:01:02:129') SELECT DTstamp FROM #table DROP…
Andrew
  • 73
  • 1
  • 1
  • 3
7
votes
3 answers

INSERT EXECUTE FORMAT Postgresql string

I want to create a function which will update the table. I am trying to run it: SELECT insert_function('asda', 1 ,1 , 'asd', 1) But I get the error: LINE 3 VALUES("asda","1","1","asd","1") column doesn't exist. When I am trying rot run: SELECT…
user565447
  • 969
  • 3
  • 14
  • 29
7
votes
3 answers

Insert value into a column in PostgreSQL

I am trying to figure out how to insert the same value into the entire column of a table? The table already exists and I have an empty column into which I would like to insert a certain value, for example, today's date. I have only found sources…
nix
  • 4,501
  • 5
  • 22
  • 19
7
votes
4 answers

How to insert multiple default rows into a table in PostgresQL

I have a table with columns taking default values: create table indexing_table ( id SERIAL PRIMARY KEY, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), ); How do I insert multiple default rows into this table? Do I have to repeat the…
Alex
  • 15,186
  • 15
  • 73
  • 127
7
votes
1 answer

How to insert multiple rows using a function in PostgreSQL

I want to insert more than one row in a table with function in PostgreSQL. This is my table CREATE TABLE mahasiswa ( nim CHAR(10), nama VACHAR(40) CONSTRAINT pk_nim PRIMARY KEY (nim) ) ; and this is the function I created CREATE FUNCTION…
nahrun
  • 73
  • 1
  • 1
  • 6
7
votes
1 answer

Duplicate entry for key 'PRIMARY' for every INSERT query I am trying in a particular table

I have the following table structure (using SHOW CREATE command just now): CREATE TABLE `ipstats` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `ip` VARCHAR(15) NOT NULL, `online` ENUM('n','y') NOT NULL DEFAULT 'y', `last_used`…
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
7
votes
4 answers

SELECT DISTINCT values and INSERT INTO table

I want to take a column with values that repeat multiple times and get that value only once and store it for later use, but at the same time I would like to get another value in the same row as that distinct column. A B C 32263 123456 …
JohnAtrik
  • 175
  • 2
  • 5
  • 14
7
votes
4 answers

Insert data from db to another db

I want to take values from my old database tables to new database tables. Old db structure: Table I: Country CountryId CountryName New db structure Table II: Countries Id Name I used the following insert query like, select 'insert into…
PoliDev
  • 1,408
  • 9
  • 24
  • 45
6
votes
4 answers

How to append two columns into one column in SQL?

I have two columns in my Table called as Workers - Technicians. In Workers I have name of workers, and in Technicians I have name of technicians who is working in company. Here is how it looks: Workers                              …
LuckySlevin
  • 695
  • 3
  • 16
  • 23
6
votes
1 answer

Pipe multiple SQL commands to psql CLI

I have a set of linux applications that are being composed together via pipes some_application | awk '{print "INSERT INTO my_table VALUES (\x27" $2 "\x27," $3 ")"' The output of which will be a series of SQL INSERT commands: INSERT INTO my_table…
6
votes
1 answer

postgresql insert a structured data into jsonb

I use PostgreSQL 10.11 and would want to enter the following structure into a jsonb field: { lead: { name: string, prep: boolean }, secondary: { { name: string, prep: boolean }, { name: string, …
Ms workaholic
  • 373
  • 2
  • 8
  • 21