Questions tagged [sql-insert]

The SQL INSERT statement allows you to insert a single or multiple rows into a table.

SQL INSERT statement adds one or more rows to a single table in a relational database.

The basic INSERT values syntax is:

INSERT INTO table [ (column1 [, column2, column3 ... ]) ]
VALUES (value1 [, value2, value3 ... ]);

The INSERT SELECT syntax is:

INSERT INTO table [ (column1 [, column2, column3 ... ]) ]
SELECT c1 [, c2, c3 ... ] FROM table

Reference

For questions regarding SQL INSERT statement use this tag instead of .

5071 questions
1
vote
1 answer

mysqli INSERT query not working no errors

I cant figure out why my php script isn't working at times it does work after deleting all data from my database table
Thamus
  • 108
  • 8
1
vote
3 answers

How to store stored procedure return value in a table or variable

I have a stored procedure in which I want to store a value returned by another stored procedure how would I do it. I tried and googled, but couldn't succeed. My code is: declare @t table (name varchar(100)) declare @MprNum varchar(20) …
Loyal
  • 773
  • 2
  • 8
  • 20
1
vote
0 answers

unable to insert value of primary key

The UserId field does not get updated with the value passed by the application, whereas all the other fields get updated. This is my insert query and other related code from my app: $sql = "INSERT INTO usermaster (UserId, UserName,…
SSUser
  • 31
  • 3
1
vote
2 answers

Insert non-duplicate data into a table from another table

I am trying to insert a non duplicate records into a table but which doing so I am unable to insert it it gives me (0 row(s) affected). And actually the table itself is empty and I am insert new records. To ignore inserting duplicate records I am…
user5731250
1
vote
4 answers

Create a table from two tables where data is in rows in one table

I have two tables linked by a user ID. I want to create a new table from both which pulls several fields from each table. In one table there is only one row per user ID, in the other there are several rows of data for each user. The first table is…
Jolo
  • 67
  • 1
  • 1
  • 9
1
vote
1 answer

How to remove a single quote from a value while inserting in SQL database

I have a long list of insert query which has a slight error. INSERT INTO `delivery_zip` (..) VALUES ("AB'C / DEF", ..), ("AB'C / DEF", ..), ("AB'C / DEF", ..), ... How do I remove the single quote after AB' from the values.
Sandeep Pariyar
  • 133
  • 2
  • 12
1
vote
1 answer

Laravel 5.2: Handling database insertions using the Laravel Queues service

Good morning! I have the following code in my Controller: $num_rows = $this->drupalRequestRowCount(); $uris = $this->drupalRequestPrepareUri($num_rows, config('constants.IMPORT_DATA_URI')); $requestHandler = new RequestHandler($uris[0]); $content =…
nicolinho66
  • 107
  • 1
  • 7
1
vote
0 answers

Validate ALL the constraints when inserting a record in Oracle

I have a table in Oracle with several constraints. When I insert a new record, Oracle raises only the "first" error. How to get all violations of my record? **********EDITED FOR LITERAL EXAMPLE**************** CREATE TABLE TEST( COL_1 NUMBER NOT…
Avhelsing
  • 81
  • 2
  • 7
1
vote
1 answer

Two unique inserts from one select

I'm using a InnoDB/memcache as a temp holder for rows not processed and placed into it's table with indexes (which slowed down the initial load by a lot and we need to handle spikes). The table is as follows memcached/innodb: c1|c2|c3|c4 I need to…
Jason K
  • 55
  • 1
  • 7
1
vote
1 answer

ERROR: UNIQUE constraint failed....but not when I use a SELECT * Statement (SQLite)

I'm having a problem. I have a table in which I want to move its data into another table. When I do : INSERT INTO rosters SELECT * FROM rosters_test All of the rows enter into the database. The problem is that the columns are out of order for the…
Kurt Leadley
  • 513
  • 3
  • 20
1
vote
1 answer

Insert into table, return id and then insert into another table with stored id

I have the following three tables: Please note that the below DDL came models generated by Django then grabbed out of Postgresql after they were created. So modifying the tables is not an option. CREATE TABLE "parentTeacherCon_grade" ( id…
RandomNumberFun
  • 638
  • 2
  • 8
  • 25
1
vote
1 answer

SQL Desc column name not accepted?

I've have created a SQL database, which I'm connected to with MySQL Workbench. I have one column that I for some reason can't use in the query, which Workbench actually recognize. My Query looks looked like this: INSERT INTO `mcfluid` (desc, type,…
RasmusGP
  • 4,696
  • 5
  • 21
  • 28
1
vote
3 answers

Sql to generate all combination from 4 tables

I have 3 tables Table1: Table2: Table3: **Users** **Posts** **Articles** Name| Title| Title| Raj Post1 Article1 Sujay Post2 Article2 Bijay Post3 …
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
1
vote
1 answer

Get the ID of inserted record after being inserted

I apologize if this question has been asked before, but I was unable to find anything like it. When the user clicks submit, a new record is inserted into my database and the ID is auto-increased by 1 - for example, if the latest record in the…
The Codesee
  • 3,714
  • 5
  • 38
  • 78
1
vote
2 answers

INSERT only when IF-condition is true

I would like to know if there is a possibility to Insert a row into a table when IF-Condition is true: SET @Value1 := '1'; SET @Value2 := '2'; IF(@Value2 >= @Value1) THEN INSERT INTO `Table` (`Row1`, `Row2`) VALUES …
Peter
  • 1,224
  • 3
  • 16
  • 28