Let us say you'd a table such as this
There's a originality constraint around the 'name' column.
How does one set #2's title to foo, and #1's title to close?
I understand you can most likely just assign temporary names to both then stick within the preferred names, but that doesn't appear such as the easiest way.
I'm using Hibernate, so any Hibernate-specific methods could be nice. This appears just like a problem that affects all RDBMSes generally though.
In Sql Server you can update both of them simultaneously:
UPDATE table SET Name = CASE WHEN ID = 1 THEN 'bar' ELSE 'foo' END WHERE ID IN ( 1, 2 )
SQL Server and
Oracle, constraints are deferred, this is exactly why you simply problem this question:
UPDATE mytable SET name = CASE name WHEN 'foo' THEN 'bar' ELSE 'foo' END WHERE name IN ('foo', 'bar')
As recommended in comments, it appears that you're by using this in
MySQL to keep an purchased list (which was before I experienced this issue).
Within this situation you might want to browse the number of articles during my blog regarding how to get it done in
MySQL more effectively: