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.

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 row into a database, inserting an item into a list.

In programming languages, in the context of insertion of an item into a container (eg. arrays, linked lists), insert is normally used to denote addition of an item at an arbitrary point (by order of items) in the container. This is as opposed to append (add to end of container), or prepend (add to the front of the container).

Do not use this tag for questions regarding SQL INSERT statement. Use tag instead.

See also ,

14336 questions
1982
votes
4 answers

Inserting multiple rows in a single SQL query?

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 ("Jane", 124, "Lloyds Office"); INSERT INTO MyTable…
rits
1048
votes
20 answers

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?
Xah Lee
  • 16,755
  • 9
  • 37
  • 43
945
votes
12 answers

"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 KEY UPDATE which implies an unnecessary update at…
Thomas G Henry LLC
  • 10,887
  • 8
  • 30
  • 32
728
votes
22 answers

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 update command ELSE run insert command What's…
Chris Cudmore
  • 29,793
  • 12
  • 57
  • 94
619
votes
23 answers

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?
kusanagi
  • 14,296
  • 20
  • 86
  • 111
602
votes
18 answers

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, but the syntax is not exactly right... please,…
Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
488
votes
11 answers

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??
Jack Kada
  • 24,474
  • 29
  • 82
  • 106
457
votes
14 answers

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
Anton
  • 9,682
  • 11
  • 38
  • 68
444
votes
8 answers

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 INSERT EXEC queries. …
Indrek
  • 6,516
  • 4
  • 29
  • 27
404
votes
13 answers

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 generated primary key item_id in the same…
Amy Neville
  • 10,067
  • 13
  • 58
  • 94
381
votes
10 answers

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 the initial value for the id column.
bbtang
  • 5,665
  • 8
  • 33
  • 27
350
votes
9 answers

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 follows: CREATE TABLE Book ID INTEGER PRIMARY KEY…
SparkyNZ
  • 6,266
  • 7
  • 39
  • 80
322
votes
16 answers

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?
Navdroid
  • 4,453
  • 7
  • 29
  • 47
294
votes
1 answer

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 identity value (called Id) using the OUTPUT clause?…
Yatrix
  • 13,361
  • 16
  • 48
  • 78
289
votes
6 answers

insert vs emplace vs operator[] in c++ map

I'm using maps for the first time and I realized that there are many ways to insert an element. You can use emplace(), operator[] or insert(), plus variants like using value_type or make_pair. While there is a lot of information about all of them…
German Capuano
  • 5,183
  • 6
  • 23
  • 35
1
2 3
99 100