Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6939693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:39:17+00:00 2026-05-27T12:39:17+00:00

I have a table with unique index on two columns, id_parent and sort_order to

  • 0

I have a table with unique index on two columns, id_parent and sort_order to be precise

+----+-----------+------------+-------------+-------------+-------------+
| id | id_parent | sort_order | some_data   | other_data  | more_data   |
+----+-----------+------------+-------------+-------------+-------------+
| 1  |         1 |          1 | lorem ipsum | lorem ipsum | lorem ipsum |
| 2  |         1 |          2 | lorem ipsum | lorem ipsum | lorem ipsum |
| 3  |         1 |          3 | lorem ipsum | lorem ipsum | lorem ipsum |
+----+-----------+------------+-------------+-------------+-------------+

Now I want to update them, their data and their sort_order in one-go. sort_order would change from 1 - 2 - 3 to, for example 2 - 3 - 1.

But when I start running update statements, unique index block me, just as expected, saying that I can’t have two rows with id_parent = 1 and sort_order = 2.
Well, I could set it 4 for now, update other rows in correct order, and then set this one.
But then, I would have to run an extra statement, and most probably add additional logic to my scripting language to determine correct order of updates.
I also use ORM, and it becomes even more inconvinient.

My question now, is there some method to make mysql temporarily ignore this index? Like starting a special transaction, in which indexes would be calculated only right before commiting it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:39:18+00:00Added an answer on May 27, 2026 at 12:39 pm

    As far as I know that isn’t possible.

    The only time I’ve seen anything like that is that you can disable non unique keys on myisam tables. But not on InnoDB and not on unique keys.

    However, to save you an update or two, there is no need to have the exact number 1, 2 and 3. You could as well have 4, 5 and 6. Right? You would use it in a order by and nothing else so the exact numbers aren’t important. It will even save you an update if you’re clever. From your example

    update table set sort_order = 4 where sort_order = 1 and id = 1 and id_parent = 1;
    

    New sort order is 2, 3, 1. And in just one update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a unique key for two columns: CREATE TABLE `xpo`.`user_permanent_gift`
I have two tables orders and orderdetails table orders (PK = id, UNIQUE index
I have a table and I'm trying to add a unique index on two
I have a table called Table with columns: ID (int, primary key, clustered, unique
I have a table in my schema that has a unique constraint on two
In Sql Server 2005, I have a table with two integer columns, call them
I have a table with a 12-column UNIQUE index. \d sales shows sales_uq UNIQUE,
If I have a joining table with two columns, TeamA and TeamB, how can
How can I efficiently create a unique index on two fields in a table
I have a table with a primary key, but I want two other columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.