insert

SQL Update Trigger

Hi, I have the following issue. We have a user table, every user has an unique email and username. We try to do this within our code but we want to be sure users are never inserted (or updated) in the database with the same username of email. I've added a BEFORE INSERT Trigger which prevents the insertion of duplicate users. CREATE TRI...

best way to generate mass insert statement in c#?

I am needing to insert a bunch of similar records into a table, and was wondering if there was a nice/easy way to do this. I know it would be easy to just build a big string, but I was hoping I could find a more graceful way to do this. ...

"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 some cost, or "INSERT IGNORE" which implies an invitation for other kinds of failure...

How can I write a subroutine for DBI inserts with varying number of values?

Hi! I'm doing a lot of insert queries, and I think it would be best to write a subroutine for it. Something like insertRow($table, @stuff_to_insert). But how can I make the subroutine dynamic when it comes to the @stuff_to_insert, which can be anything from 1-5 arguments? ...

With MySQL, how do I insert into a table on condition that the value does not exist in another table?

I have a MySQL database and I would like to insert some values into one table, assuming that a particular value that I am inserting does not match a value in a different table. Here is a simplified/example structure: Table: invites id : int (auto-increment index) name : varchar message : varchar Table: donotinvite name...

Inserting into Oracle the wrong way - how to deal with it?

I've just found the following code: select max(id) from TABLE_NAME ... ... do some stuff ... insert into TABLE_NAME (id, ... ) VALUES (max(id) + 1, ...) I can create a sequence for the PK, but there's a bunch of existing code (classic asp, existing asp.net apps that aren't part of this project) that's not going to use it. Should I ...

Optimizing the speed of insertion in java.util.Map/Set

Hi all, is there a way to optimize the speed of the insertions in a java.util.Collection by specifying the order of the items ? For example java.util.Set<String> set = java.util.TreeSet<String>(); will this solution: set.add("A"); set.add("B"); set.add("C"); set.add("D"); set.add("E"); be faster than this one (random order) ? set...

jQuery - insert item into array at a specific index

I am looking for a JavaScript array insert method, in the style of: arr.insert(index, item) Preferably in jQuery, but any JavaScript implementation will do at this point because I can't believe the trouble I'm having finding such a basic function! Thanks for your help. ...

Inserting an object to the db using hibernate, only if it doesn't exist

Let's say I have a mapped User object with a user_id as a primary key, and a mail column with a unique constraint. I want my program to save a User object to the users table only if it doesn't exist. I can do the following thing in my insert function: begin transaction query for a user with the given mail if it doesn't exist, create a...

Inserts are 4x slower if table has lots of record (400K) vs. if it's empty

(Database: Oracle 10G R2) It takes 1 minute to insert 100,000 records into a table. But if the table already contains some records (400K), then it takes 4 minutes and 12 seconds; also CPU-wait jumps up and “Free Buffer Waits” become really high (from dbconsole). Do you know what’s happing here? Is this because of frequent table extents...

MySQL INSERT INTO ... SELECT throws Error 1064

Trying to duplicate some rows in a table but just change the ssreportid column from 4 to 6: INSERT INTO ssreportparticipant (ssreportid, sssurveyparticipantid) VALUES SELECT 6, sssurveyparticipantid FROM ssreportparticipant WHERE ssreportid = 4 The error says #1064 near 'select 6, ...' but if I just run the select clause, it selects...

Inserting rows into a database in ASP.NET

I am new to .NET, and I'm can't seem to figure out something that should be simple. I want to insert a row into a table, and initialize it with values that aren't bound to data controls. Specifically, I have a CreateUserWizard control on a page. In the CreatedUser method, I want to insert a row into a databse I created called "users" tha...

PHP and MYSQL maximum variable length?

I'm trying to do an INSERT into a mysql db and it fails when any of the values are longer than 898 characters. Is there somewhere to get or, better, set this maximum value? I'll hack the string into chunks and store 'em in separate rows if I must, but I'd like to be able to insert up to 2k at a time. I'm guessing this is php issue as us...

linq to sql Insert not working on deployed server(IIS)

title speaks for itself, db.ExecuteCommand("INSERT INTO tCSVFile(fileName, fileContent, mimetype, timeCreated) VALUES({0}, {1}, {2}, {3})", filename, EncodeTo64(CreateCSVFile(header, rows)), "text/csv", DateTime.Now ); this works fine from the virtual server but on iis inserting causes nothing to happen. Also tried this.. tCSVFile...

Possible to INSERT INTO a table with values from another table?

So say I want to... insert into tableA, 2 variables from tableB, but only rows that are in tableB that have 1 of the variables equal to a certain thing... hmm let's see if I can be more specific... i want to create a new row in tableA with the userid and courseid from tableB for every row of tableB that has a courseid of 11 please ad...

How can I merge data within a DB table by a SQL statement?

I have an interesting problem for Interbase. I have a record set which amongst other things has a data entry field and a timestamp for each record. I would like to be able to copy the timestamp from records so that at the end of the day the final field will read along the lines of: TIMESTAMP <Carriage return> <carriage return> Origina...

How can I insert text into a string in Perl?

If I had: $foo= "12."bar bar bar"|three"; how would I insert in the text ".." after the text 12. in the variable? ...

Copy data from one existing row to another existing row in SQL?

OK so I suck at SQL and I always have to ask for help, not sure what my disconnect is because I don't have any problem with programming C like languages, here is my challenge: I have a table full of tracking data for as specific course, course number 6. Now I have added new tracking data for course number 11. Each row of data is for o...

How to properly insert/delete in a binary search tree in C?

I kinda have to put my previous C questions on hold cause this one is more important now... I have already coded the insert and delete functions on my binary search tree but the delete function is incomplete. There's a couple of things I need help in... 1) Is my insert function good or can it be improved somehow? 2) My delete function...

Programatically insert a Word document into an existing document (Word 2007)

I have a Word 2007 document that I want to insert an exsiting Word document into - while preserving the header/footer, graphics, borders etc of both documents. I'm doing this using the Word API in C#. It sounds pretty simple, I mean surely you just use the "InsertFile" method... except that in Word 2007 the "insert file" functionality ...