Jump to content

Updating a unique field


stubarny

Recommended Posts

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

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.

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 .....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.