Questions tagged [insert]
Insert is an action to add information to a larger container that the information should reside within. Some examples include inserting a file into a file system, inserting a record into a database, or inserting an item into a list.
13,946
questions
1871votes
4answers
3.0mviews
Inserting multiple rows in a single SQL query? [duplicate]
I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and Office.
INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("...
952votes
19answers
741kviews
How to insert an element after another element in JavaScript without using a library?
There's insertBefore() in JavaScript, but how can I insert an element after another element without using jQuery or another library?
907votes
12answers
955kviews
"INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either:
ON DUPLICATE ...
683votes
23answers
799kviews
Solutions for INSERT OR UPDATE on SQL Server
Assume a table structure of MyTable(KEY, datafield1, datafield2...).
Often I want to either update an existing record, or insert a new record if it doesn't exist.
Essentially:
IF (key exists)
run ...
581votes
16answers
835kviews
Insert multiple rows WITHOUT repeating the "INSERT INTO ..." part of the statement?
I know I've done this before years ago, but I can't remember the syntax, and I can't find it anywhere due to pulling up tons of help docs and articles about "bulk imports".
Here's what I want to do, ...
579votes
23answers
474kviews
Insert new item in array on any position in PHP
How can I insert a new item into an array on any position, for example in the middle of array?
467votes
11answers
460kviews
Exporting data In SQL Server as INSERT INTO
I am using SQL Server 2008 Management Studio and have a table I want to migrate to a different db server.
Is there any option to export the data as an insert into SQL script??
415votes
8answers
854kviews
SELECT INTO a table variable in T-SQL
Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn't allow it.
Along the same lines, you cannot use a table variable with SELECT INTO or ...
393votes
14answers
345kviews
PostgreSQL function for last inserted ID
In PostgreSQL, how do I get the last id inserted into a table?
In MS SQL there is SCOPE_IDENTITY().
Please do not advise me to use something like this:
select max(id) from table
353votes
10answers
669kviews
How to set initial value and auto increment in MySQL?
How do I set the initial value for an "id" column in a MySQL table that start from 1001?
I want to do an insert "INSERT INTO users (name, email) VALUES ('{$name}', '{$email}')";
Without specifying ...
353votes
13answers
380kviews
Get the new record primary key ID from MySQL insert query?
Let's say I am doing a MySQL INSERT into one of my tables and the table has the column item_id which is set to autoincrement and primary key.
How do I get the query to output the value of the newly ...
320votes
9answers
487kviews
INSERT IF NOT EXISTS ELSE UPDATE?
I've found a few "would be" solutions for the classic "How do I insert a new record or update one if it already exists" but I cannot get any of them to work in SQLite.
I have a table defined as ...
287votes
16answers
569kviews
How to copy a row and insert in same table with a autoincrement field in MySQL?
In MySQL I am trying to copy a row with an autoincrement column ID=1 and insert the data into same table as a new row with column ID=2.
How can I do this in a single query?
267votes
1answer
349kviews
How do I use an INSERT statement's OUTPUT clause to get the identity value?
If I have an insert statement such as:
INSERT INTO MyTable
(
Name,
Address,
PhoneNo
)
VALUES
(
'Yatrix',
'1234 Address Stuff',
'1112223333'
)
How do I set @var INT to the new row's ...
246votes
11answers
248kviews
Export specific rows from a PostgreSQL table as INSERT SQL script
I have a database schema named: nyummy and a table named cimory:
create table nyummy.cimory (
id numeric(10,0) not null,
name character varying(60) not null,
city character varying(50) not null,...