Questions tagged [insert]

A core statement in SQL that does what it says on the tin: inserts data into a table.

Filter by
Sorted by
Tagged with
1 vote
1 answer
71 views

mysql bulk insert with constraints

I created a table like this, CREATE TABLE Leaderboard( userId bigint not null, matchId bigint not null, score mediumint not null, country CHAR(10), tournamentId int not null ) ...
umarkaa's user avatar
  • 35
0 votes
2 answers
22 views

(PostgreSQL) Insert a tuple containing specific value in a column linked to a sequence

I started writing this post as a question but, while reproducing the error, I found the solution in the PostgreSQL documentation. So I'll share the solution here for the community. A PostgreSQL 14 ...
ValerioOliveira's user avatar
0 votes
0 answers
46 views

How to get last executed statement on a particular table in Oracle?

Trying to identify what ghost process is inserting records into a particular table. Is there a way to get the exact query?
Dhaval Mohandas's user avatar
-2 votes
2 answers
60 views

Replace "INSERT" by "UPDATE"

I'm working with some tables in an SQL-Server database, and I'm doing some crucial modifications. In order not to loose everything when I mess up, I decided to do a "Generate script" (data ...
Dominique's user avatar
  • 521
1 vote
1 answer
37 views

Moving records between tables in CockroachDB is taking too long

I have a requirement where I have to move records from table original_table to table new_table for the last N days. Below is a small sample of my basic script that does this. while True: result = ...
Brunaldo's user avatar
0 votes
0 answers
52 views

How to insert data into temporary table from the table having encrypted columns in sql server

I am trying to insert data into a temporary table(#table1) from the table(table2) having encrypted column in it. I am getting below error while trying to insert data into temporary table from the ...
Prathap r's user avatar
0 votes
1 answer
160 views

question about using Insert where not exists instead of if not exists then

I have a procedure that insert data to table where the data doesn't exists. right now it's done in two steps : check if the data exists already, if not, insert it i want to change it to do INSERT ...
dexon's user avatar
  • 47
0 votes
2 answers
91 views

SQL Server inserts fails silently

I have a stored procedure that inserts some rows into a table. Sometimes it seems to fail (can't find the new records) although I know the statements did execute. The code I use is bellow. After ...
Eyal Hasson's user avatar
0 votes
1 answer
49 views

Move row of a table to an inherited table in PostgreSQL

I have tables created as such: BEGIN; CREATE TABLE tag ( id SERIAL, name VARCHAR(255) UNIQUE NOT NULL, description VARCHAR(511) NOT NULL DEFAULT '', PRIMARY KEY(id) )...
SK19's user avatar
  • 101
0 votes
0 answers
57 views

Mariadb Triggers after multiple insert, update one table one one time

CREATE TRIGGER after_composers_insert AFTER INSERT ON composers FOR EACH ROW UPDATE listings SET composer_name = NEW.composer_name WHERE composer_id = NEW.composer_id; CREATE TRIGGER ...
Alain Lagune's user avatar
-1 votes
2 answers
64 views

SQL breaking my query where there is NULL value

Here is my sql statement and the error I am facing: SQL> INSERT INTO COUNTRY(COUNTRY_CODE) select unique(country_code) from AIRPORTDEMODATA where country_code IS NOT NULL; 2 INSERT INTO COUNTRY(...
Java_Beginner's user avatar
0 votes
1 answer
35 views

Is commit of first insert necessary if second insert has constraint depedent on first insert?

Using MariaDB I am running an insert on one table and then trying to run another insert on second table. Due to a constraint the second insert should only succeed if the first one was successful. If I ...
loris's user avatar
  • 103
0 votes
1 answer
206 views

Auto-increment [id] field in a table in an SQL-Server database

I have different tables, containing an id field. That field is typically defined as id (PK, int, not null). Normally, when adding an entry to a table, I add the value of the id field myself, but I'm ...
Dominique's user avatar
  • 521
0 votes
1 answer
135 views

In PostgreSQL, what is the `index_predicate` for in `INSERT`?

The docs on INSERT say: If an index_predicate is specified, it must, as a further requirement for inference, satisfy arbiter indexes. Note that this means a non-partial unique index (a unique index ...
Nathan Long's user avatar
1 vote
1 answer
141 views

Lazily Evaluate Insert Arguments If Constraint Violated

create table a ( b text not null unique, c text not null ); -- Sleeps for 1 second as expected. insert into a (b, c) values ('d', pg_sleep(1)); -- Sleeps for 1 second even though record is ...
Mario Ishac's user avatar
0 votes
1 answer
29 views

Delete records from table that are not in the file being inserted

I have a Snaplogic pipeline that queries a web application every night and loads the data into a SQL Server table. I use the 'Update' snap to add new records or add any changes. The goal is that the ...
Matt's user avatar
  • 271
1 vote
1 answer
366 views

How to handle deadlocks while multiple batch inserts?

I need suggestions/ideas of handling a issue with deadlocks. I'm having multiple batch inserts commands to same table: insert into ip (id, p_id, m_type, m_id, sha256, path) VALUES ($1, $2, $3, $4, $5, ...
KaliTheGreat's user avatar
1 vote
1 answer
80 views

insert trigger to auto-set key fields for composite primary key

Basically the next step for Error "UNIQUE constraint failed" with composite primary key: I created a trigger after insert to set SEQ to the highest SEQ plus one if it's less than one. ...
U. Windl's user avatar
  • 125
1 vote
1 answer
148 views

SQL Server stored proc locking, serialization

Stored proc in SQL Server INSERT INTO table1 value sets A , B Value set A has as one of its parameters: (SELECT TOP 1 cashbalance - 1 FROM table1 WHERE userid = __ ORDER BY createdUTC, ID) Value set B ...
M S's user avatar
  • 21
1 vote
0 answers
147 views

Copy rows and change corresponding values

I have 4 tables Tables are used to store product attributes and its values in different languages I'm trying to copy attribute (copy in same table to new row and increment/change some values). First ...
Webzber's user avatar
  • 11
0 votes
1 answer
233 views

What is the most straightforward way to create subtypes and supertypes at the same time?

I hope this isn't too basic a question, but I am hoping that the DB engineers here will help me out. Do relational DBs usually have a straightforward way of doing the following?: Create a supertable ...
Logos Masters's user avatar
0 votes
1 answer
204 views

MSSQL - Insert Into Select number from global count table and update the global count for each row then inserted

Not sure I've articulated that well in the title, so here goes... I have three tables Table1 ID NewNames 10 some row data 11 some more row data Table2 ID OldNames 1 my old data 2 and more data ...
Les's user avatar
  • 1
0 votes
1 answer
42 views

Compositing ordered SQL tables without Joins

I'm currently exploring some weird ways of doing things and was wondering if anyone has any experience with the following methodology. Background I have a handful of NF3 tables, and NF1 source data. ...
Vocoder's user avatar
  • 117
0 votes
1 answer
90 views

Migrate columns from table A to table B, and update A with a reference to B

I have a table A with some columns that need to be migrated to a new table B. But I also need to create a column in table A to reference the id's from the new columns in the table B. I've tried doing ...
Warix3's user avatar
  • 1
0 votes
1 answer
239 views

SQL Server: Inserting empty value (zero-arity INSERT) [duplicate]

I made test table: create table tmp (id BIGINT NOT NULL IDENTITY PRIMARY KEY) Now I want to insert a value: insert into tmp () values(); and it complains: SQL Error [102] [S0001]: Incorrect syntax ...
gavenkoa's user avatar
  • 509
0 votes
1 answer
74 views

MySQL gives Unknown column error when forward engineering database from diagram

I have a MySQL EER diagram the I forward engineer into a database. I also use the forward engineer feature to generate insert statements for data automatically. After entering about 120 rows of data I ...
SlowlySwift's user avatar
2 votes
1 answer
60 views

Inefficiency of index in SELECT requests after large INSERT requests on myisam tables on MariaDB 10.6

This is my first post on this website. Please don’t hesitate to indicate me if there is any problem in my post. I have a new issue when migrating from MariaDB 10.1 to MariaDB 10.6 on indexes with ...
Tom Tom's user avatar
  • 21
0 votes
0 answers
98 views

Problem with inserting a new row - unknown column name reported missing

I'm new to SQL Anywhere. I have a SQL Anywhere 11 database that was not designed by me. I'm trying to insert a new row in a table with let's say 3 columns. When I execute the sql statement insert into ...
user2274824's user avatar
0 votes
1 answer
599 views

Insert rows into a (postgres) table where the first col is a static value and the second col is the result of a SELECT DISTINCT from another table

I haven't had to use SQL in years and I'm clearly rusty. I have a situation where I'm trying to insert multiple rows into table A. There are two columns of data to be inserted, the first is a "...
Amy Lee's user avatar
0 votes
0 answers
46 views

How do I automatically insert a row into parent table when a row is created in a child table?

I am working on a MySQL database that has to treat organizations and people as interchangeable in some instances and not others. Because of this, I created a table called LegalEntity as a superclass. ...
SlowlySwift's user avatar
2 votes
2 answers
1k views

PostgreSQL: Insert dynamic columns and values from jsonb argument

This question relates to Update dynamic column names using keys from jsonb argument and my code is based on the answer provided there by https://dba.stackexchange.com/users/3684/erwin-brandstetter I'm ...
Russell Turner's user avatar
0 votes
1 answer
937 views

SET BIGINT fieldname value to 0 automatically if inserting empty string

How do I do something like : INSERT INTO tablename SET customer_id = '' WHERE <condition>; customer_id is BIGINT NULL Default NULL But when I execute SET customer_id = '' it gives Incorrect ...
anjanesh's user avatar
  • 279
1 vote
2 answers
1k views

How can I insert into a Postgres table with a unique constraint without waiting on concurrent transactions?

I have a table like this in a Postgres database: CREATE TABLE tabwithunique ( id SERIAL PRIMARY KEY, key BIGINT NOT NULL UNIQUE, value BIGINT NOT NULL ); I want to design a statement that ...
Curtis Fenner's user avatar
1 vote
2 answers
261 views

MariaDB: Large INSERT SELECT query failed without generating an error

I have a large complicated neuroscience dataset that I am attempting to organize in a database for concurrent and consistent access with my lab. This is my first foray beyond much smaller experiments ...
Chris Cox's user avatar
1 vote
2 answers
810 views

Insert values and add values to foreign key

I have two tables: CREATE TABLE est ( est_id serial PRIMARY KEY , est_nom varchar(70) ); CREATE TABLE bm ( id serial PRIMARY KEY , est_nom int , nom varchar(70) , CONSTRAINT FK_bm_est FOREIGN KEY(...
David Palacios's user avatar
1 vote
2 answers
227 views

Is it safe to use lastval/currval for multiple inserts?

Lets say I have those tables: CREATE TABLE buildings ( id_building serial4 NOT NULL, street text NULL, CONSTRAINT buildings_pkey PRIMARY KEY (id_building) ); CREATE TABLE families ( ...
Sotis's user avatar
  • 306
0 votes
1 answer
120 views

Insert Statement on large MySQL table does not terminate

I have a MySQL database with several tables. One table (InnoDB) is quite large (about 490 million rows). The table consists of 4 columns: id: int(11), auto_increment term: varchar(255) docId: int(11) ...
Philipp's user avatar
-1 votes
1 answer
5k views

Stored procedure to Insert data into table with select statement and argument parameter [duplicate]

I am creating a stored procedure which will populate my table with data passed from procedure argument and from other table. I have a table with three columns (cart_id, product, sold_quantity). Now, I ...
Jaimin Sutariya's user avatar
0 votes
2 answers
745 views

PostgreSQL, INSERT INTO SELECT DISTINCT generates more rows?

I have a large PostgreSQL table (NOT indexed) with duplicates so I ran the following query to eventually end up with a unique rows table: INSERT INTO newTable(Field1, Field2, Field3) SELECT DISTINCT ...
Anvil's user avatar
  • 11
3 votes
3 answers
1k views

MySQL: How to make Trigger to insert row in another table?

Please read everything, included the notes and edits at the end Problem I have a MySQL DB with 3 different table: To save users mysql> describe users; +-------------+-----------------------------...
Cromega08's user avatar
1 vote
0 answers
215 views

update trigger after insert on same table

So, I'm supposed to make a trigger that applies md5 to a row after an INSERT was made on it. Here is what I came up with: delimiter $$\ create trigger pd_encrip before insert on usuario\ for each row\ ...
Jade Fernandes's user avatar
1 vote
0 answers
155 views

PL SQL code that Inserts data from a different table and gives new id values from the same table that the data is being inserted

What could I change to make this insert work and give a new ID value on each row I am inserting? Right now it's giving all the inserted rows the same ID number. Sadly, I can't use triggers and ...
Kristofers Kaprāns's user avatar
1 vote
0 answers
109 views

Auto Increment ID based on 2 columns

I have table called Logs. it has 4 columns ID, USER_ID, USER_TYPE, USER_ACTION where USER_ID is unique USER_TYPE is unique for every USER_ID and USER_ACTION can be anything 1,2,3 or A to Z. USER_ID ...
Zoheb Patel's user avatar
3 votes
1 answer
856 views

How To Optimize a Query That Aggregates Then Duplicates a Large Number of Records in a Single Table

In the following post, J.D. brings up that I have a poorly performing query. I am running this query on SQL Server 2019 Standard Edition (query plan was generated in Development Edition) Let's take a ...
David Rogers's user avatar
0 votes
2 answers
2k views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
Arun's user avatar
  • 13
0 votes
1 answer
399 views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
Arun's user avatar
  • 13
0 votes
1 answer
26 views

how to import several columns from diferent tables/databases into one

To be a bit clear I have 3 different tables with several columns each I want to kind of create a final table to help me explain myself better Table A: id a2 a3 a4 a5 a6 1 11 12 13 14 15 Table B: ...
Alejandro85's user avatar
1 vote
1 answer
151 views

help with mariadb after update trigger

I have a table that is shared among 7 other tables and I want to synchronize a new part is added to the parts table. new rows are created in each of the 7 other tables, using the part_id from the ...
Doug Gardiner's user avatar
0 votes
1 answer
127 views

Cloning a table into a separate schema in SQL Server

On an SQL Server database that I manage, there are a fair number of backup clone tables lying around, littered throughout the dbo schema. I am about to create such a backup clone now, and I would like ...
Janus Bahs Jacquet's user avatar
0 votes
3 answers
191 views

On duplicate, conditional update, not working

I have a table with two columns : id(int), data(text) data holds an array of strings. I want to insert strings into it, if they're not already present. Searched a bit, came up with this : INSERT INTO ...
lyeaf's user avatar
  • 177

1
2 3 4 5
17