stubarny Posted May 12, 2012 Share Posted May 12, 2012 Hello, I am trying to run the following SQL code which replaces the string "Warehouse-Workers" with the string "Warehouse" in the website_page_name field of the website_page_names table: UPDATE website_page_names SET website_page_name=(REPLACE (website_page_name , "Warehouse-Workers", "Warehouse")); The problem is that website_page_name is a unique field and the query falls over whenever a duplicate is found. Please could you tell me how to workaround? (I want to not update any records that would cause a duplicate if updated) Thanks, Stu Link to comment https://forums.phpfreaks.com/topic/262447-updating-a-unique-field/ Share on other sites More sharing options...
The Letter E Posted May 14, 2012 Share Posted May 14, 2012 Hello, I am trying to run the following SQL code which replaces the string "Warehouse-Workers" with the string "Warehouse" in the website_page_name field of the website_page_names table: UPDATE website_page_names SET website_page_name=(REPLACE (website_page_name , "Warehouse-Workers", "Warehouse")); The problem is that website_page_name is a unique field and the query falls over whenever a duplicate is found. Please could you tell me how to workaround? (I want to not update any records that would cause a duplicate if updated) Thanks, Stu That means there is another row in your database where website_page_name = "Warehouse" You need to use a "unique" value(meaning it's not in another row for that column) when inserting or updating the table, otherwise you'll get an error. Link to comment https://forums.phpfreaks.com/topic/262447-updating-a-unique-field/#findComment-1345218 Share on other sites More sharing options...
Barand Posted May 14, 2012 Share Posted May 14, 2012 If you use the IGNORE keyword' date=' the update statement does not abort even if errors occur during the update. Rows for which duplicate-key conflicts occur are not updated. Rows for which columns are updated to values that would cause data conversion errors are updated to the closest valid values instead. [/quote'] UPDATE IGNORE tablename SET ..... Link to comment https://forums.phpfreaks.com/topic/262447-updating-a-unique-field/#findComment-1345268 Share on other sites More sharing options...
fenway Posted May 19, 2012 Share Posted May 19, 2012 But then, of course, one of the values won't have changed. Link to comment https://forums.phpfreaks.com/topic/262447-updating-a-unique-field/#findComment-1346837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.