insert-update

SQL - Table Design - DateCreated and DateUpdated columns

For my application there are several entity classes, User, Customer, Post, and so on I'm about to design the database and I want to store the date when the entities were created and updated. This is where it gets tricky. Sure one option is to add created_timestamp and update_timestamp columns for each of the entity tables but that isn't...

Insert/Update on SQL Server 2005 without using Stored Procedures

I'm trying to do the classic Insert/Update scenario where I need to update existing rows in a database or insert them if they are not there. I've found a previous question on the subject, but it deals with stored procedures, which I'm not using. I'd like to just use plain SQL SELECT, INSERT and UPDATE statements, unless there's somethi...

Is there a way to do an "INSERT...ON DUPLICATE KEY UDPATE" in Zend Framework?

I would like to use "ON DUPLICATE KEY UPDATE" in Zend Framework, is this possible? Example INSERT INTO sometable (...) VALUES (...) ON DUPLICATE KEY UPDATE ... ...

How do I Insert or Update (or overwrite) a record using NHibernate?

I need to write a row to the database regardless of whether it already exists or not. Before using NHibernate this was done with a stored procedure. The procedure would attempt an update and if no rows were modified it would fallback to an insert. This worked well because the application doesn't care if the record exists. With NHibernat...

Does DB2 have an "insert or update" statement?

From my code (Java) I want to ensure that a row exists in the database (DB2) after my code is executed. My code now does a select and if no result is returned it does an insert. I really don't like this code since it exposes me to concurrency issuses when running in a multi-threaded environment. What I would like to do is to put this l...

How to round a Column defined as Float on INSERT and UPDATE in SQL Server 2005

I am working on a Database that uses the Float data type to store values that should only be 2 decimal positions (dollars and cents). Using Float appears to work OK, as long as the person updating the Float column does a ROUND. Of course, this does not always happen and then when a SUM is done it is always off a few pennies from what is ...

Cant update Tabled Mapped in Linq2Sql

Hi there!, Im having troubles right now, i cant update a table X in DBDataContext, so this is my snippet, by the way when I Update just one table it works! but when I Insert and then update, It Throw Exception ... "cant cast object from System.Int32 to System.String type" { using (DBDataContext db = new DBDataContext()) ...

LINQ to SQL, Failed on db.SubmitChanges()

Im getting an Exception when I try updating, Insert works perfectly.. so this is: A first chance exception of type 'System.InvalidCastException' occurred in System.Data.Linq.dll Another cue... is possible to insert in one table first and then update another table and finally submitchanges() all in same code-block? I also comment InsertO...

Inserting records at a time

I have 2 table TableA and TableB I want to insert all records at a time from TableA to TableB if the records are not in TableB Please help thank you ...

Writing custom Insert/Update command for OleDbDataAdapter

Hello! I am using OleDbDataAdapter to fill a table in the DataSet. The problem is that select sql statement is very complex (using left joins to get data from numerous tables) and OleDbCommandBuilder can't write an insert/update statement for me. I was wondering what is the best course of action here? There aren't that many columns in ...

Insert binary std::string using ODBC into BLOB column

can somebody give me an example how to insert binary std::string using ODBC and C++ into BLOB column, please? EDIT: Duplicate of How to INSERT binary std::string into BLOB (MySQL). ...

how can i insert a column value at a specified row

how can i insert a column value at a specified row ...

JPA merge does not appear to work

Hi, I'm running the following code to update the database according to the data I read from CSV file. I've tried to debug, and check the console and it's running through the whole 800 records. I don't get any error, but only the first record is inserted. If I'm using persist instead of merge, I got "Cannot persist detached object" error....

SQL Server & update (or insert) parallelism

Dear Boffins I got a large conversion job- 299Gb of JPEG images, already in the database, into thumbnail equivalents for reporting and bandwidth purposes. I've written a thread safe SQLCLR function to do the business of re-sampling the images, lovely job. Problem is, when I execute it in an UPDATE statement (from the PhotoData field ...

How to insert JPEG into a SQL Server 2000 database field of image type using Transact SQL

Hi, I'm trying to figure out how to insert a .JPG file into a SQL Server 2000 database field of type image using Transact SQL. Thanks. ...

How do I update if exists, insert if not (aka upsert or merge) in MySQL?

Is there an easy way to INSERT an row when not exists, or to UPDATE if it exists, using one MySQL query? ...

Rails - User Input for Multiple models on a single form - How

This is basically a nested form question, albeit with only one field that belongs to a parent model. My data entry form collects data for a model - however I also need to collect one other a data element/value (UserID) that actually goes into a parent record that will be created with the detail record. AFAIK Rails expects each form fie...

how to know if last operation was insert or update when using insert on duplicate update in mysql and php?

I am using PHP and MySQL. If I use an INSERT ON DUPLICATE UPDATE SQL statement, then how do I know if the last operation was an successful insert and not an update or unsuccessful insert? The assumptions are the table in question does not use an auto increment, so I can't use a mysql_insert_id to help me find out. ...

INSERT INTO..SELECT..ON DUPLICATE KEYS ambiguous ids

Hey there, I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id | promoter | generation | turnover | payed | +----+----------+------------+----------+-------+ | 1 | 4 | 1 | 10 | 0 | | 3 | 4 | 5 | 100 | ...

Insert using single insert statement.

Hi, I want to insert the data in my table tblSubscriptions and I only want to use one insert statement. I am going to insert data for every userId in User Table. The following SQL doesnot work. Insert tblSubscriptions (UserID, ProductID, isACtive, SubscriptionDays, Price, MonthlyPrice, ProductType, CurrencyID) Values ((Select userID Fr...