FAQ Database Discussion Community


Multiple insert SQL oracle

sql,oracle,sql-insert,identity-column,oracle12c
How do you do multiple insert with SQL in Oracle 12c when you have an identity column? INSERT ALL INTO Table1 (Column2) Values (1) INTO Table1 (Column2) Values (2) SELECT * FROM dual; where Table1 has column1 as an identity, will set the identity column to have the same value...

Insert the same fixed percentage into multiple rows at once

mysql,sql,sql-update,sql-insert
I have data in this manner: ID SUB Marks 1 English 25 2 Maths 22 3 Science 15 4 English 16 How would I sum the "marks" value with a fixed percentage and give total marks of each ID at once? For example, if I have a fixed percentage of...

MySQL inserts very slow into MEMORY table

mysql,sql-insert,database-performance
I am trying to optimize a large (68K row) insert into a staging table. I created the table as a MEMORY engine table, and there are no indexes or foreign keys at all. When my ETL process starts inserting, the inserts execute, but very slowly; the full load takes over...

Error in php sql statement ($stmt2 is returning false but I dont know why)

sql,prepared-statement,sql-insert,bindparam
I am getting this error (Call to a member function bind_param() on a non-object ) for my prepared statement as below which I know means that there is some error in the sql statement but I cannot see any error at all. I have been staring at this for a...

How to have SQL increase ID by 1 on a column using an insert statement

sql,sql-insert
I am trying to insert multiple rows into SQL. The table contains an external ID column that when using the APP increases this ID by one. The external ID is not the Primary key, but another ID in the table. Currently last external ID is 544. I want to insert...

Violation of PRIMARY KEY constraint 'PK_Address'. etc…what am I doing wrong?

sql-server,sql-insert
Evening all. I am fairly new to SQL but have been doing quite a bit of fooling around. I am following a guide I found online to learn SQL in 21 days and I am having a bit of trouble figuring out what the error I am receiving is causing....

Last id not inserted in sub loop

php,mysql,sql,sql-insert
my insert query is like this. i am getting $lastaddressid but i can't insert that last inserted id in for loop, because it automatically takes the last inserted id for all records of addressgroup. What's wrong? if($insertgroupRes) { for($k=0; $k<count($_POST['address']); $k++) { $address = (isset($_REQUEST['address'][$k])) ? $_REQUEST['address'][$k] : ''; $insertcontact...

How to insert a string if a table returns null?

sql,sql-server-2008,testing,sql-insert
I'm attempting to adapt a query someone else wrote to do some testing. There are several queries in this file that will pull data and as long as no results are generated then everything is good. There are several spots in this query that I don't understand but the only...

Insert values into dynamically created table in the same stored procedure

sql,sql-server,stored-procedures,sql-insert,dymamic
My task is: create a table and insert n values into the table in the same stored procedure. CREATE PROCEDURE PROC @tableName nvarchar(30), @nRows int AS BEGIN IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(@tableName) AND type in (N'U')) DROP TABLE [dbo].[@tableName ] DECLARE @SQLString NVARCHAR(MAX) SET @SQLString...

WHERE clause with INSERT statement, “Incorrect Syntax” at the WHERE, and IF NOT EXISTS running regardless of if record exists

sql,sql-server-2008,where,sql-insert
I have this INSERT query: INSERT INTO Appointments (StaffID, CustomerID, TimeSlot, AppDate) VALUES (1, 11, 1, DATEADD(day, 1, GETDATE())) WHERE NOT EXISTS (SELECT * FROM Appointments WHERE StaffID = 1 AND CustomerID = 11 AND TimeSlot = 1 AND AppDate = DATEADD(day, 1, GETDATE())); Yet it says "Incorrect syntax near...

how to data store in mysql using form in php

php,mysql,fetch,sql-insert
I face a little problem. i cant find out problem in my code. My INSERT query is running fine but my data is not inserted in sql table using php form. when i run this code, my code cannot fatch the data which is filled by a user. Here is...

SQL Syntax error while using python to import values into MySQL Database

python,mysql,sql,import,sql-insert
New to python and MySQL and am teaching myself from internet and books. I am struggling to import values into a database table. I keep getting an error stating that the SQL syntax is incorrect. Using Python 2.7.9 and MySQL Connector 5.6 on a Window 8 machine. Here is the...

Insert data into two tables, one depend on another

codeigniter,sql-insert
For example I have such structure in database: table1: [id] [content] table2: [id] [table1_id] and I want insert some data at the same time into this two tables, but the problem is with [table1_id] which is primary key from table1. How can I insert it?...

php mysql insert statement using variables

php,mysql,sql-insert
my php code which is throwing errors is as follows: $stmt = $con->prepare('INSERT INTO listOfRides (address, time) VALUES ('$address', '$time')') ; I have looked at other posts and it seems I am using the variables correctly with the single quotes around them however the following error is being shown when...

insert a single value into new created column

sql,oracle,plsql,sql-insert
First of all: It sounds pretty basic to me, but i did not find anything on this topic that comes close. I am using pl-sql and have a table thats contains records. Now i have created a new column and want to insert an entry when specific conditions given. Something...

update/insert data into table from table - ORA-00904

sql,oracle,sql-update,sql-insert,sqlcode
I am trying to insert/update data into table but I´m getting ORA-00904 - invalid identifier. With tables definitions like this: CREATE TABLE "TST"."R0_RL_EST_SHARE" ( "ID" NUMBER(19,0), "BUILDING_SOCIETY_SHARE" CHAR(1 CHAR), "EDITED_BY_USER" CHAR(1 CHAR), "OBJECT_CREATED_ON" TIMESTAMP (6), "OBJECT_TYPE" VARCHAR2(2048 CHAR), "OBJECT_UPDATED_ON" TIMESTAMP (6), "OBJECT_VERSION" NUMBER(19,0), "REAL_ESTATE_SHARE_D" NUMBER(19,0), "REAL_ESTATE_SHARE_N" NUMBER(19,0), "MORTGAGE_OBJECT_ID" NUMBER(19,0), "REAL_ESTATE_ID"...

SQL Insert into and Select multiple columns?

mysql,sql,performance,select,sql-insert
So I have a tables that look something like this: Communication: (Calls made) Timestamp FromIDNumber ToIDNumber GeneralLocation 2012-03-02 09:02:30 878 674 Grasslands 2012-03-02 11:30:01 456 213 Tundra 2012-03-02 07:02:12 789 654 Mountains 2012-03-02 08:06:08 458 789 Tundra And I want to create a new table that has all the distinct...

Postgres timestamp: what is the number after the dot and how to remove it?

postgresql,timestamp,sql-insert
I'm inserting new records to my Postgres database, using PHP. In my query i add the function now() to write the date and the time of the insert. $query = "INSERT INTO myTable(field1, field2, date, field4, field5) values('" . pg_escape_string($value1) . "', '" . (int) pg_escape_string($value2) . "', NOW(), '"...

Insert ids from other select

sql,sql-server,sql-insert
I want to insert all possible combinations to the SalesInformationRead. All userIds, fileIds, groupIds & competitionIds (primary keys) will need to get inserted. And the other problem is that they don't have any relationship thats binds them. The following query returns exception: Subquery returned more than 1 value. This is...

Insert with multiple selects

sql,oracle,oracle-sqldeveloper,sql-insert,insert-select
I have a SQL request that return some ora-01427 error: single-row subquery returns more than one row INSERT INTO my_table (value0, value1, value2, value3) VALUES((SELECT MAX(value0) FROM my_table), '5', (SELECT DISTINCT(value2) FROM another_table), '8'); The thing is, I need two hard-coded values, I need a value from a select that...

Multiple inserts into SQLite getting data from other tables

sql,sqlite,sql-insert
In SQLite, I have a simple message board where I want to timestamp when each user first sees any post. CREATE TABLE messages ( message_id INTEGER PRIMARY KEY, mb_topic_id INTEGER NOT NULL REFERENCES mb_topics(mb_topic_id), message_poster INTEGER NOT NULL REFERENCES users(user_id), message_content TEXT, message_post_time TIMESTAMP DEFAULT (strftime('%s', 'now')) ) CREATE TABLE...

csv file import to mysql database using php facing error to import

php,csv,mysqli,sql-insert,mysqlimport
Importing CVS File (Microsoft Office Excel Comma Separated Values File (.csv)) in phpmyadmim using php script. When i am importing CSV File then its not importing properly into the database. Line is terminate by "," Please suggest me how i make it line terminate "auto", i am attaching sample file....

Updating a database using arrays

php,mysql,arrays,multidimensional-array,sql-insert
I'm trying to update a database using arrays, but I can't seem to do that. I can only update it using strings, and numbers, but not arrays. Then I tried to echo out the string, number AND the array, just to see if I made an mistake in making the...

Error duplicate key on INSERT with SELECT NOT EXISTS

postgresql,sql-insert
How could happen this? IntegrityError: (IntegrityError) duplicate key value violates unique constraint "r_u_pkey" DETAIL: Key (r_id, u_id)=(2660, 10182) already exists. 'INSERT INTO r_u(r_id, u_id) SELECT %s, %s WHERE NOT EXISTS ( SELECT 1 FROM r_u WHERE r_id = %s AND u_id = %s )' (2660, 10182, 2660, 10182) There is...

How to insert new row in Postgres table? [duplicate]

sql,postgresql,sql-insert,phppgadmin
This question already has an answer here: Postgres sql insert query syntax error 1 answer i'm using for the first times Postgres and i'm experiencing problems adding a new row by SQL code. Here is my table structure: And here is the code that i'm executing: INSERT INTO recensione...

Insert a new record inside the Java class [duplicate]

java,mysql,jdbc,sql-insert
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I have this method in my Java class, to insert a new record to my DB (a date and thee booleans values). private void setTodayInfo(HttpSession session, String date){...

Trigger on insert and update that adds modification date

sql-server,sql-insert,sql-server-triggers
I'm making a simple table with names, emails etc, but I also have a ModifiedDate. My idea is to use a trigger after both insert and update, and insert the current date. Thus if anyone does anything (except delete) to that column, the date should reflect that. This is however...

Update prices in mysql

mysql,sql,sql-update,sql-insert
This is how my articles table looks like: (tbl_articles) ID | SHORT_DESCRIPTION | DESCRIPTION | GROSS | NET 1 | v00556 | valve washroom | 9.00 | 7.49 etc. My supplier provided me a new price list, in this format (tbl_supplier) SHORT_DESCRIPTION | DESCRIPTION | GROSS | NET v0056 |...

OOP INSERT INTO statement not working

php,sql,oop,sql-insert
I am creating a very simple message board to learn OOP-styled programming. The purpose is to display posts that are saved in the database, and beneath the displayed posts, you can add a new post to the database which will also display on the page. I am having trouble with...

SQL inserts slow - “pre populate with blank rows??”

sql-server,performance,sql-update,sql-insert,insert-update
I have an .exe that compares a vbTab delimited .txt file with an SQL table. Updates to the table's existing records goes very fast. Inserts into the table for new records is quite slow. As I'm new to SQL, I'm wondering if my idea is crazy talk: I thought that...

Error in sql syntax;

php,mysql,sql-insert
This is the error i get; 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_query("INSERT INTO `user`(fname,lname,email,'user-id') VALUES ('$fnam' at line 1 Can someone please help me figure out what the...

Stored Procedure for insert

sql-server,stored-procedures,datatable,syntax-error,sql-insert
I am taking a datatable as parameter in my stored procedure and I am trying to insert a few of its column in one of the database tables but I don't know the correct syntax. This is what I have tried ALTER PROCEDURE [dbo].[spInsertInvoice] @tblInvoice [TypeExcel] READONLY AS BEGIN SET...

INSERT INTO syntax issue

php,mysql,sql-insert
I keep having a syntax error issue even when I try to resolve it. Here is the error message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rue de vergennes, 06xxxxxxxx, [email protected])' at...

Combining INSERT statements in a data-modifying CTE with a CASE expression

sql,postgresql,case,common-table-expression,sql-insert
My question is some kind of extension to Erwin Brandstetter's excellent answer in this thread on the correct use of WITH. My old query looks like this: WITH x AS ( INSERT INTO d (dm_id) SELECT dm_id FROM dm, import i WHERE dm.dm_name = i.dm_name RETURNING d_id ), y AS...

Oracle 11g Insert Statement into Multiple Tables

sql,oracle,oracle11g,triggers,sql-insert
I am currently having trouble trying to execute multiple statements at the same time. I keep getting this error when trying to run the following INSERT statements: INSERT INTO report_header ( report_number, company_id, user_id, entry_date) VALUES ( 6797, 15967, 84, TRUNC(SYSDATE)); INSERT INTO report_detail (part_id, condition_id, uom_id, dvc_id, cqh_id, alt_part_id,...

SQL Trigger Insert After Modify Value

triggers,sql-insert
I'm looking to make a trigger on new insert to modify a value. The scenario is as follows. When a new entry to the table is added, and if the ObjectTypeID is between 684 and 750, update the quality value to 100. From what I have read so far, I...

I have to insert data with the other table field USING PHP

php,mysql,sql,sql-insert
Please Find below query for inserting the data but in h_id field, I have to insert another table field id all variable value I have to get from POST method INSERT INTO m_d_details(h_id, name, h_name, surname, village, resi, mobile_no)VALUES('SELECT id from head_family ORDER BY id DESC LIMIT 1', '$mname', '$mhname',...

Return id from postgresql insertion

sql,postgresql,sql-insert
In an external application I want to do the following: Insert an entry to table A Insert a bunch of entries to table B, with the id of my newly inserted item in A as a foreign key So the tables would look like this: A(_id, data) B(_id, other_data) _id...

MySQL Foreign Key Constraint Fail

php,mysql,pdo,foreign-keys,sql-insert
So, to clarify things: I know why this is failing. The question is: How to work around that? This is my setup: The referencing table is users and the referencing column is id, the referenced table is user_data, and the referenced column is id. I want to store the email,...

INSERT RANDOM values from one database to other

sql,sql-server,database,sql-insert
I have a project, and i need to insert values to NORTHWIND database from other database, AdventureWorks2012. I know how to insert manualy values to one table in one database, but i can find out how to insert from another database. I FORGOT TO SAY THAT I NEED RANDOM VALUES...

How to insert multiple data to a table with auto_increment primary key column?

sql,sqlite,sql-insert
So I'm using SQLite 3.6 and tried to insert multiple data to my table which has 3 columns (1 AI PK) using INSERT INTO 'tablename' SELECT 'data1' AS 'column1', 'data2' AS 'column2' UNION SELECT 'data3', 'data4' UNION SELECT 'data5', 'data6' UNION SELECT 'data7', 'data8' somehow it didn't work and I...

want to insert duplicate data in mysql table with new relations id's

mysql,sql,database,phpmyadmin,sql-insert
I have a table with columns ID, tag_ID, W_ID and data is in below format ID, tag_ID, W_ID 1 25 124 2 25 128 3 25 135 4 25 189 5 25 254 Now I want to insert tag_ID = 28 with all w_ID which have tag_id = 25 and...

After inserting a row in mysql, the latest row climbs up based on date

mysql,sql,sql-insert
Insertion of a row in a table does not make it the last row, but instead inserts a row above certain rows. insert into table (revenueSB40, revenueSM40, sum, eedate) values(100,200,300,'2015-05-17'); Last few rows: | 41200 | 80620 | 121820 | 2015-05-11 00:00:00 | | 35440 | 86100 | 121540 |...

Insert row into table with only a primary key field

sql,postgresql,primary-key,auto-increment,sql-insert
Googling around told me to try this: insert into Plan default values; but I got: null value in column "id" violates not-null constraint or this: insert into Plan (id) values (null); but I got the same thing. The examples were for SQL: is there something different for PostgreSQL? Table structure:...

Adding a column of data

mysql,sql-update,sql-insert
Not been able to find something that matches what I am setting out to teach myself, so here goes: I have added a column (called status) to an existing table (called fruit). All values in this new column are currently null. Other columns in this table are id (primary key...

Insert into a table two values using two “FROM” clauses

sql,ms-access,sql-insert
Is there a way to insert into a table two values using two "FROM" clauses? I try to insert percentile values - Exposure and Awareness: INSERT INTO tbReport (Exposure, Awareness) SELECT MAX([q_Exposure]) FROM (SELECT TOP 30 PERCENT [q_Exposure] FROM tbQuestions WHERE q_Exposure IS NOT NULL ORDER BY [q_Exposure]), MAX([q_Awareness]) FROM...

build insert statement error Https has already been declared

c#,asp.net-mvc-5,sql-insert
I have a method which takes multiple images from the UI and stores them in the cache, when this has finished it calls a method which then references the cache pulls the images out and then passes them to the database, at the moment this insert statement is currently doing...

PHP / MySQLi: How to prevent SQL injection on INSERT (code partially working)

php,mysql,mysqli,sql-injection,sql-insert
I am new to PHP and hope someone can help me with this. I would like to store two values (an email and a password) in a MySQL db using PHP. The input is passed to the PHP page via Ajax in jQuery (through an onclick event on a website)....

Android SQLiteDatabase Insert Syntax Error

syntax-error,android-sqlite,sql-insert
I've searched around and found people with similar issues, yet not quite the same. I'm receiving an SQLite syntax error, but I cannot locate the bad syntax. Please help! I created an SQLite Database in DatabaseAdapter.java, seen here: static class DatabaseHelper extends SQLiteOpenHelper{ private static final String DATABASE_NAME = "mealdatabase";...

Use DEFAULT or INTEGER value as a SQL function's argument

sql,postgresql,function,concurrency,sql-insert
I am making a SQL function to perform a smart insertion and manage a many to many table (a trigger wouldn't work as one value is variable). Here is a minimum set for the example: link_foo_to_bar (foo_id int, bar_id int) foo (id serial, name character varying) And here's my sql...

Insert varchar coupon code in database table

php,mysql,sql-insert
I have a website based on reward point. I want to store the 'coupon code' in the database to a record which user has used which code to recharge their account to buy anything. I create an insert into table in php to insert the coupon for the user. I...

proper way to format text to insert in database using php

php,mysql,utf-8,sql-insert,text-formatting
I try to insert this information in Mysql database $mytext = "this is a word in french d'origine francaise"; Then the PHP sql code: $sql = "INSERT INTO tchapter (content) VALUES ('". $mytext ."')"; It will send me an error because i have a ' apostrophe character in the $mytext,...

Why is this SQL INSERT failing without raising and exception?

c#,sql-server,azure,sql-insert
I have a problem with an INSERT into a table on Azure SQL which is failing - returning a -1 on rows affected using the ExecuteNonQuery command. The Table looks like this: and the code is like this: private void SaveUrls(ArrayList alUrls) { int rows = 0; this.Cursor = Cursors.WaitCursor;...

How can I use DECLARE clause in a statement on jdbc?

java,mysql,jdbc,prepared-statement,sql-insert
I am currently trying to use a DECLARE clause in a preparedStatent with jdbc. The code that I wrote is: statement.executeUpdate(" declare @variable int set @variable = "+timer+" INSERT INTO table1 values (ip, protocol, counter, timer) SELECT ip,protocol,counter,@variable FROM table2 ORDER BY counter DESC LIMIT 5 OFFSET 0 ;"); What...

MySQL Insert Statement foreign key auto add pk

php,mysql,foreign-keys,primary-key,sql-insert
I have a fairly complicated database set up with lots of foreign key relationships and want to know if there is an easy way to insert an entry into one of these tables. This is the table that holds some of the foreign keys. CREATE TABLE package ( id INT...

how to insert the xml data to sql server using c#?

sql,xml,stored-procedures,sql-insert
I am beginner to the C#, I need to insert my XML file to SQL table pro-grammatically XML file have five nodes called root, name, subject, sno and queries, I will listed below <root> <name> MyName </name> <subject> newsubject </subject> <queries> <sno> 1 </sno> <query> This is the query one...

I got an SQL error, trying to insert a form to the database

php,mysql,syntax-error,sql-insert,mysql-error-1064
I have no idea of what i am doing wrong. I'm trying to insert a form, to my table. Insert failed: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-v, youtube-c, portfolio-link,...

PHP Script insert even if file upload/field element is disabled

php,mysql,insert,sql-insert
Hi I can't seem to pinpoint what's wrong. I have a form with elements. Could you check the script? I just know it lacks something but a noob like me just doesn't know. Basically when the Smart Money radio button is selected, the BPI is disabled,and vice versa. It should...

SQL Server, double insert at the exact same time, unicity Bug

sql-server,sql-server-2012,sql-insert
I am facing trouble when the following code is called two times almost at the same time. DECLARE @membershipIdReturn as uniqueidentifier=null SELECT @membershipIdReturn = MembershipId FROM [Loyalty].[Membership] WITH (NOLOCK) WHERE ContactId = @customerIdFront AND IsDeleted = 0 IF (@membershipIdReturn IS NULL) //InsertStatementHere The calls are so close (about 3 thousandth...

CakePHP Create() not inserting all fields in SQL query

cakephp,sql-insert
I am trying to pass information from a form to a new record in the database. My form: <?php echo "<div>" . $this->Form->create('Machines', array('action' => 'add')) . "</div>"; echo "<div>" . $this->Form->input('name') . "</div>"; echo "<div>" . $this->Form->input('type', array('type' => 'select', 'options' => array( 'Stand-alone' => 'stand-alone', 'Host' => 'host',...

INSERT SQL Updatable Query using proper MS Access cmd Command

c#,sql,visual-studio-2013,sql-insert,ms-access-2013
Access databse query fails when i run on another machine Config Below Microsoft Word 2013 Visual Studio 2013 Windows 8.1 (64 bit) While On The Another Machine The Same Query Runs Config Below Microsoft Word 2010 Visual Studio 2010 Windows 7 (32 bit) The Query Below con.Open(); string cb =...

Can other users break into my sql sequence of operations?

sql,postgresql,concurrency,auto-increment,sql-insert
I do insert operations into the database (Postgres) and then immediately take the last serial id. If 10 people do the same thing, can they break the sequence of my database operations? INSERT INTO table VALUES (DEFAULT,...); SELECT currval(pg_get_serial_sequence('table','column')) as inserted_id; I'm afraid that may happen situation like: INSERT INTO...

T-SQL Insert when not in table and when max timestamp Issue

sql-server,tsql,sql-server-2012,max,sql-insert
I am trying to insert rows from one table to another that are not in the one I am moving them to. I also want to only move the ones that have the highest datestamp. (I want to only insert rows that are not in tb1 and have the max...

adding date from calendar to sql server 2008

c#,asp.net,sql-server,datetime,sql-insert
I am working on a project in asp.net c# which I am getting date from two calendars and storing them in database fields specified as datetime in SprintsN table, sql server 2008 database. But I am getting an exception Exception: insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate) values('1week', 'incomplete','5','2015-05-01 12:00:00','2015-05-07...

How to insert records faster

java,mysql,prepared-statement,sql-insert
I have to read records from CSV file and store them in Mysql database. I know about "LOAD DATA INFILE" but in my case I have to get single record from file, check if it is in valid format/length etc and then store it in database. // list to store...

ORA-22992 Remove references to LOB in remote table issue

oracle,casting,subquery,sql-insert,lob
I am trying to insert into table CAPTURED_DATA_01 with multiple select statement.I am able to insert the value EVENT_ID,ENV_ID,BRAND_ID,BP_ID but now i also want to insert the SUBSCRIPTION_ID value which is coming i will get from using the select statement in remote table. The query i have tested and runs...