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

learn more… | top users | synonyms (1)

2
votes
1answer
26 views

Insert if something changed other than specific column

I have a table with many columns but my snippet is simplified. I have the trigger shown below but how can I have it so that nothing is inserted if only the created_at column has changed? ALTER ...
0
votes
1answer
27 views

How do I prevent multiple row insert?

I set up a playground MySQL database for users and I'd like to prevent multiple row (large) inserts. That is, if there will be over N rows after INSERT operation, then raise an error and do not ...
17
votes
4answers
2k views

How to limit maximum number of rows in a table to just 1

I have a configuration table in my SQL Server database and this table should only ever have one row. To help future developers understand this I'd like to prevent more than one row of data being added....
0
votes
1answer
36 views

MySQL insert with sub select slow

We are using Python and LOAD DATA INFILE to load data from CSVs into our staging database. From staging we have sql scripts moving the data into our actual production database. LOAD DATA INFILE is ...
0
votes
0answers
14 views

On Duplicate Update Multiple Keys (not or) With And

I have friends table user_id_1 | user_id_2 | points 1 2 99 ADD UNIQUE (user_id_1, user_id_2) works perfectly, but i run this query; INSERT INTO friends (user_id_1,user_id_2) ...
0
votes
1answer
71 views

T-SQL insert with output expression [closed]

insert Table1 OUTPUT inserted.ID, s.[Id] INTO @Inserted select s.[Field1], s.[Field2], from @TableVariable s why is s.[Id] marked by red line ? Is it non-correct syntax to save value in @...
1
vote
0answers
34 views

INSERT MySQL stored procedure executes twice when it contains a select statement as well [closed]

I have a very simple MySQL stored procedure as shown below: BEGIN INSERT INTO listing_offers (lo_active, lo_amount, lo_amount_number, lo_contract_reference,lo_created, lo_currency, ...
0
votes
1answer
25 views

Mysql columns mutual exclusion

I want to create a table which has 2 columns that would only allow one of them to have value in the same row. I tried with CHECK constraint but it not working correctly Ex: SQL Fiddle schema ...
1
vote
1answer
23 views

Insert column name as value

Consider the following, in PostgreSQL: drop table test ; create table test (result1 text, red smallint, green smallint, blue smallint, results2 text) ; insert into test values ('red',1,2,3) ; I ...
0
votes
1answer
55 views

How to handle HUGE 16GB SQL file?

I've abc.sql file exported from MySQL Table. This abc.sql file is 16 GB in size with around 28 million insert statements. I'm looking for option to store it in SQL Server Database. Couple of ...
2
votes
0answers
55 views

Insertion into postgres database stops (hangs) after table reaches a certain size without error

We are currently trying to insert a large amount of data, about 27 million records with 200 columns, into a single table in a postgres 9.4 database. (Yes it is probably better to refactor the table ...
0
votes
2answers
62 views

INSERT OR REPLACE INTO + SELECT as source in Oracle

I have two tables A and B. I want to insert B's content into table A. The issue is there's a row in B that already exists in A. I've searched and I found some answers talking about MERGE, but no ...
1
vote
1answer
49 views

What is the fastest way to insert data into MySQL memory table?

I need to insert 10M+ records into a MySQL memory table. A naive approach was to pipe records using shell, e.g. $ tail -10 ~/Desktop/test.sql INSERT INTO `test` (`a`, `b`) VALUES (4, 5); INSERT INTO ...
2
votes
2answers
49 views

Using Variables to contain column names for SQL Server Merge statemtns

I'm trying to automate the column list grab for a merge job, and running into a bit of a head scratcher. I don't want to have to manually type out all of the column names, and thought I may be able to ...
0
votes
1answer
16 views

A different number of AFTER INSERT trigger alarms in SQLite and SQL Server

I have trigger CREATE TRIGGER [Foo] AFTER INSERT ON [Bar] BEGIN UPDATE Log SET count = count + 1; END When i execute query insert into Bar (ColumnName) values ('SomeValue1'), ('SomeValue2'), (...
0
votes
0answers
53 views

Very Very Veeery slow insert queries

I am writing here because I`ve already spent days reading tutorials, other topics in here, and trying different configurations. The project : Fashion website with ~200k products which should be ...
0
votes
1answer
43 views

INSERT and UPDATE in Trigger

I have created a trigger so I could insert every row in a backup table CREATE OR REPLACE TRIGGER xyz AFTER INSERT ON table_1 REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW BEGIN INSERT INTO table_2 (...
3
votes
1answer
47 views

How to maintain trees and their roots in SQLite

I have a (SQLite) database with a table representing nodes in a forest (set of trees): create table "Node" ( "id" Text primary key, "parent" Text references "Node" ("id") -- parent node ...
0
votes
0answers
9 views

Inserting data from external PC faster than from localhost

I've been benchmarking the performance of a new virtual server in order to find out the best engine and database structure for my setup. Currently I am using python with mysql-connector both on the ...
0
votes
1answer
102 views

How to insert values into a table with default values from a select query in PostgreSQL?

Is it possible to INSERT values into a PostgreSQL table from a SELECT statement and to use DEFAULT values for the columns that are null? In my case, the SELECT statement is selecting from JSON. In ...
3
votes
2answers
80 views

Inserting rows with WHERE condition

Structure 1 table named: scan 2 columns named: id, and date Problem I have two working queries, a SELECT and then an INSERT which I would like to merge together creating a INSERT where the ...
0
votes
2answers
59 views

Insert the same time, it is possible to happen?

Good evening. I have a doubt about inclusion in the database. A common example is a user account where the user names must be unique. In the following logic: User enters data into a form. Data are ...
0
votes
1answer
39 views

Trigger with multiple inserts based on JSON data

I am using sqlite and have its json1 extension available. I have the following tables (reduced to a minimal example): -- table filled from external source, -- with only a little possible impact on ...
0
votes
0answers
15 views

Insert rows from another table while updating source table with IDs

I have this table structure table A: A.id (autogenerated) A.data table B B.id (autogenerated) B.A_id B.data B.anotherData There are some rows that were inserted into table B, without corresponding ...
1
vote
1answer
35 views

Is inserting into a table with a foreign key constraint slower than inserting without constraint?

When using MySQL (actually, Aurora), will inserting into a table with a foreign key constraint be slower than the same table without the constraint?
0
votes
3answers
104 views

Is it possible to allow missing value inserts in mysql instead of requiring “NULL” in the query? [closed]

I am writing a script to insert values from a file into a mysql database. The script reads lines from the file and constructs insert queries from them. Sometimes particular columns are empty, so an ...
-2
votes
1answer
60 views

Cannot update nor insert data to datetime field [closed]

I was trying to insert data through one web application I am developing and I could not insert data, while I was troubleshooting what the problem is, I saw that I can not neither edit datetime field ...
0
votes
2answers
93 views

How to insert numerous data into temporary table?

I'm building a program which generates a T-SQL query in following form: DECLARE @In TABLE (Col CHAR(20)) INSERT INTO @In VALUES value1, value2... value1000 GO INSERT INTO @In VALUES value1001, ...
1
vote
1answer
33 views

INSERT INTO using the RETURNING values from another INSERT

I'd like to do something like this: INSERT INTO table2(name) INSERT INTO table1(name, address) VALUES ('me', 'home') RETURNING name; And then I would expect a new record in table2 with 'me' in ...
1
vote
1answer
34 views

Insert multiples rows/columns - PostgreSQL 9.2

I've got a table that has several columns, But I need to insert data into two columns of that table. I need to add data into those columns, from a select statement. Would it be something like: ...
0
votes
3answers
25 views

How to insert/combine values from multiple tables?

I have multiple tables (12 for each month) that have 3 columns each ("code", "test_name", "value") Example: January code | test_name | value 0001 name1 17 0002 name2 45 0005 ...
-1
votes
1answer
36 views

Select and Insert for all data - Need help querying [closed]

At a first glance, this is my query INSERT INTO T2 SELECT T1.*, T3.DATETIME, T3.STATEID FROM T1 WHERE T3.DATETIME BETWEEN '01-NOV-15' AND SYSDATE LEFT OUTER JOIN T3 ON (T1....
0
votes
1answer
58 views

postgresql insert from select query, plus static values

Referring to How to insert values into a table from a select query in PostgreSQL?, I would like to INSERT into a table rows from another, specified by a SELECT DISTINCT, plus some static values, ...
0
votes
1answer
19 views

InnoDB, Writing TRIGGER to INSERT into tables

Table1 "user_address" Field "u_id" Field "street_name" Field "locality_name" Table2 "street_master" Field "s_id" Field "s_name" I am supposed to write a trigger which BEFORE INSERT ON user_address(...
1
vote
1answer
57 views

Inserting rows into a truncated table will increase the size?

Today I came across this question. Everyone knows truncating table won't reduce the actual size of DB, in my scenario I have 5 tables on a DB which almost occupied 50 GB, so if I truncate all the ...
6
votes
1answer
115 views

Why would a procedure sometimes hang executing SELECT…INTO #Temp2 FROM #Temp1 JOIN LocalTable…?

We have several stored procedures, called by jobs, that follow a specific pattern (designed to minimize blocking). Some of these procs tend to hang on occasion, running up the CPU, tempdb allocations, ...
0
votes
1answer
75 views

Insert into different tables, but same data

If I have multiple insert into commands going and some of the column names are the same, do I still state them? For example: insert into MOVIE (MOVIE_ID, TITLE, RATE) values ('00001','Titanic', '...
1
vote
1answer
69 views

Xquery, insert, Trigger and no place to squeeze stored procedure

I have a Stored procedure, which is, basically, xquery pulling data from xml and inserting it into multiple tables. Once it's inserting into last of the mentioned tables, the trigger fires up and then ...
3
votes
1answer
78 views

Convert a lookup value to foreign key when a query is run

Currently we have a legacy system running queries on a Postgres server to update/insert records. One of the obstacles we are having is that we have to convert text values to the correct foreign key ...
0
votes
1answer
85 views

Postgres insert query max length or number of VALUES parameters

I'm trying to find a way to speedup population of my db. I'd like to use COPY as suggested here, but I have only access to my db, not to the entire server. All other tips worked good for me, but ...
1
vote
0answers
45 views

DB2 : Dynamic Result Sets, Duplication in Sending output to File

What I am trying to do here is to Generate insert scripts for selected tables in my database in DB2 10.5 LUW. I have modified a procedure available here as below. CREATE PROCEDURE Create_Inserts ( ...
3
votes
1answer
76 views

Unpredicatable single insert performance on SQL Server table

I have inherited a system that sometimes exhibits extremely poor single record insert performance. The table is something like 8 million rows, so is relatively large but not exceptionally so. The ...
10
votes
4answers
328 views

Progress of SELECT INTO statement

Our ETL flow has a long-running SELECT INTO-statement, that's creating a table on the fly, and populating it with several hundred million records. The statement looks something like SELECT ... INTO ...
2
votes
2answers
296 views

Speeding up insert in SQL Server

I have a stored procedure which inserts some records in a few tables. In couple of tables at least , the inserted records number 10000+. Not more than 15K though. Takes 3-5 mins for this procedure to ...
0
votes
1answer
29 views

Every “INSERT” query check a combination of column's records

Unfortunately, my mind has stacked right now and i would like to design a really simple DB schema. What i want? In a simple table, for instance Table1, there are two different columns, Series and ...
0
votes
0answers
28 views

Split data from a column into multiple rows and split data from other column into new column in MySQL

I want split data's separated by comma(,) from a column into multiple rows and also with this I want split data's from other column into multiple new columns. Finally result will insert into new ...
-1
votes
1answer
55 views

What is the optimized way to fill table values based on it's previous columns values and from other table column values?

CREATE TABLE TEST2 ( RowID INT IDENTITY(1,1), Ratio INT ) CREATE TABLE TEST ( RowID INT IDENTITY(1,1), Col1 INT, Col2 INT, Col3 INT ) Now, I want to insert values in table ...
0
votes
2answers
159 views

Trigger to compare inserted value with value from another table

I have two tables: Stockitem (serialno, qty) serialno is the primary key and Order(serialno,orderno,qty) orderno and serialno are the primary keys. I want to create a trigger in order to ensure ...
3
votes
3answers
95 views

SELECT + INSERT or INSERT alone

I have an application where several devices send data every second to my server. On the database I have a table with the devices and another table with the data sent every second. The first time a ...
0
votes
1answer
134 views

MySQL Using a trigger to update quantity on another table if part is used

I am new to triggers but want to know how I can use one in my database. I have created a table for a maintenance log, a parts inventory, and a parts_used junction table. When maintenance is carried ...