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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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