c#,sql,entity-framework,code-first,on-duplicate-key
I remember when I used to do EF I would create a table with Identity and in the class I would attribute the id column with [DatabaseGenerated(DatabaseGeneratedOption.Identity)] so I am assuming that your code should be modelBuilder.Entity<MyBase>() .Property(c => c.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); ...
mysql,sql,sql-update,on-duplicate-key
Use a case statement... Update tbl set points = CASE WHEN ID = 1 then 05 when ID = 2 then 10 when ID = 3 then 825 when ID = 4 then 48 END Working fiddle: http://sqlfiddle.com/#!9/6cb0d/1/0...
I suspect your problem is related to this question: MySQL behavior of ON DUPLICATE KEY UPDATE for multiple UNIQUE fields From the accepted answer: UPDATE in ON DUPLICATE KEY UPDATE is performed if one of the UNIQUE field equals the value to be inserted It sounds like you are expecting...
php,mysql,timestamp,on-duplicate-key
As far as I can see, the problem with your queries might be because you made timestamp field nullable `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Try making it NOT NULL - since you have valid default value for it, MySQL won't complain you have not provided the value...
mysql,sql,sql-insert,on-duplicate-key
Removing the parenthesis around the duplicate key update expressions should do the trick.
mysql,ruby,sequel,on-duplicate-key
It is possible to cause Sequel to execute a function on the RDBMS using the Sequel.function() method To execute MySQL's native LAST_INSERT_ID() and pass the column id as its argument, pass the column name as a symbol as the second argument: Sequel.function(:last_insert_id, :id) The Dataset#on_duplicate_key_update method accepts a hash of...
php,mysql,database,insert-update,on-duplicate-key
for first question you can use this query: delete from logs where user IN (SELECT * from (select user FROM logs GROUP BY user HAVING COUNT(user) > 1) tempTable); for second question since you already have primary key you cannot use on duplicate key update on user column. But you...
mysql,sql,select,insert-into,on-duplicate-key
What about: INSERT INTO songs(ID) SELECT DISTINCT songsID FROM iTunesImport WHERE (songsID IS NOT NULL) AND songsID NOT IN (SELECT ID FROM songs) ...
mysql,sql,insert,sql-insert,on-duplicate-key
If the combination of roll and sub should be unique, you should define such a key in your table: ALTER TABLE student ADD CONSTRAINT student_uq UNIQUE(roll, sub) Note that if you do this, you don't have to explicitly create the index you're creating, the constraint will create on for you....