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 ,

13601 questions
1782
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
870
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
  • 10,023
  • 8
  • 26
  • 30
868
votes
19 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
  • 14,535
  • 9
  • 32
  • 41
642
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
  • 28,156
  • 12
  • 52
  • 92
560
votes
15 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
  • 29,873
  • 18
  • 80
  • 125
545
votes
22 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
  • 13,070
  • 19
  • 78
  • 106
527
votes
7 answers

Insert text with single quotes in PostgreSQL

I have a table test(id,name). I need to insert values like: user's log, 'my user', customer's. insert into test values (1,'user's log'); insert into test values (2,''my users''); insert into test values (3,'customer's'); I am getting an error…
MAHI
  • 7,205
  • 10
  • 34
  • 46
447
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
  • 22,354
  • 29
  • 75
  • 103
396
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
  • 5,946
  • 4
  • 26
  • 27
359
votes
12 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
  • 8,537
  • 10
  • 36
  • 64
326
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,015
  • 7
  • 30
  • 26
301
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
  • 5,336
  • 6
  • 33
  • 67
301
votes
12 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
  • 8,009
  • 11
  • 48
  • 88
264
votes
15 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
  • 3,851
  • 7
  • 26
  • 47
255
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
  • 12,038
  • 13
  • 39
  • 73
1
2 3
99 100