Swap primary keys in mysql










0















I am trying to achieve the same thing as asked in this question sql swap primary key values but I can't seem to get it running with newer mysql versions becausue of the error message Error Code: 1706. Primary key/partition key update is not allowed since the table is updated both as 't' and 't2'.



My table would look like this



id name
---------
1 john

id name
---------
2 jim


and expected result would look like this



id name
---------
2 john

id name
---------
1 jim


Is there any "one-liner" for that?










share|improve this question



















  • 2





    update your question and show the related sql code

    – scaisEdge
    Nov 14 '18 at 9:11











  • Please show some sample data and expected output on what you are trying to do ?

    – Madhur Bhaiya
    Nov 14 '18 at 9:14











  • done, I copied the example from the answer to the linked question

    – jPO
    Nov 14 '18 at 9:16











  • Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

    – Madhur Bhaiya
    Nov 14 '18 at 9:55











  • I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

    – jPO
    Nov 14 '18 at 9:56















0















I am trying to achieve the same thing as asked in this question sql swap primary key values but I can't seem to get it running with newer mysql versions becausue of the error message Error Code: 1706. Primary key/partition key update is not allowed since the table is updated both as 't' and 't2'.



My table would look like this



id name
---------
1 john

id name
---------
2 jim


and expected result would look like this



id name
---------
2 john

id name
---------
1 jim


Is there any "one-liner" for that?










share|improve this question



















  • 2





    update your question and show the related sql code

    – scaisEdge
    Nov 14 '18 at 9:11











  • Please show some sample data and expected output on what you are trying to do ?

    – Madhur Bhaiya
    Nov 14 '18 at 9:14











  • done, I copied the example from the answer to the linked question

    – jPO
    Nov 14 '18 at 9:16











  • Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

    – Madhur Bhaiya
    Nov 14 '18 at 9:55











  • I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

    – jPO
    Nov 14 '18 at 9:56













0












0








0








I am trying to achieve the same thing as asked in this question sql swap primary key values but I can't seem to get it running with newer mysql versions becausue of the error message Error Code: 1706. Primary key/partition key update is not allowed since the table is updated both as 't' and 't2'.



My table would look like this



id name
---------
1 john

id name
---------
2 jim


and expected result would look like this



id name
---------
2 john

id name
---------
1 jim


Is there any "one-liner" for that?










share|improve this question
















I am trying to achieve the same thing as asked in this question sql swap primary key values but I can't seem to get it running with newer mysql versions becausue of the error message Error Code: 1706. Primary key/partition key update is not allowed since the table is updated both as 't' and 't2'.



My table would look like this



id name
---------
1 john

id name
---------
2 jim


and expected result would look like this



id name
---------
2 john

id name
---------
1 jim


Is there any "one-liner" for that?







mysql primary-key swap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 9:14







jPO

















asked Nov 14 '18 at 9:08









jPOjPO

1,1581017




1,1581017







  • 2





    update your question and show the related sql code

    – scaisEdge
    Nov 14 '18 at 9:11











  • Please show some sample data and expected output on what you are trying to do ?

    – Madhur Bhaiya
    Nov 14 '18 at 9:14











  • done, I copied the example from the answer to the linked question

    – jPO
    Nov 14 '18 at 9:16











  • Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

    – Madhur Bhaiya
    Nov 14 '18 at 9:55











  • I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

    – jPO
    Nov 14 '18 at 9:56












  • 2





    update your question and show the related sql code

    – scaisEdge
    Nov 14 '18 at 9:11











  • Please show some sample data and expected output on what you are trying to do ?

    – Madhur Bhaiya
    Nov 14 '18 at 9:14











  • done, I copied the example from the answer to the linked question

    – jPO
    Nov 14 '18 at 9:16











  • Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

    – Madhur Bhaiya
    Nov 14 '18 at 9:55











  • I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

    – jPO
    Nov 14 '18 at 9:56







2




2





update your question and show the related sql code

– scaisEdge
Nov 14 '18 at 9:11





update your question and show the related sql code

– scaisEdge
Nov 14 '18 at 9:11













Please show some sample data and expected output on what you are trying to do ?

– Madhur Bhaiya
Nov 14 '18 at 9:14





Please show some sample data and expected output on what you are trying to do ?

– Madhur Bhaiya
Nov 14 '18 at 9:14













done, I copied the example from the answer to the linked question

– jPO
Nov 14 '18 at 9:16





done, I copied the example from the answer to the linked question

– jPO
Nov 14 '18 at 9:16













Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

– Madhur Bhaiya
Nov 14 '18 at 9:55





Did you try the other answers in the linked question ? Like this:stackoverflow.com/a/26584576/2469308

– Madhur Bhaiya
Nov 14 '18 at 9:55













I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

– jPO
Nov 14 '18 at 9:56





I am not even trying because the approach is the same and the error message would be that one of the values is a duplicate. Approach with decode would deliver a message that the parameter count is incorrect.

– jPO
Nov 14 '18 at 9:56












1 Answer
1






active

oldest

votes


















0














I believe that the easier and safer way to do it is to leave the primary key as it is and swap the values of the other columns, should give you the same results






share|improve this answer




















  • 1





    It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

    – Madhur Bhaiya
    Nov 14 '18 at 9:53












  • This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

    – jPO
    Nov 14 '18 at 9:54











  • Okay^^ I'll change my answer

    – Snowy Heart
    Nov 14 '18 at 9:54











  • This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

    – jPO
    Nov 14 '18 at 10:02










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296477%2fswap-primary-keys-in-mysql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I believe that the easier and safer way to do it is to leave the primary key as it is and swap the values of the other columns, should give you the same results






share|improve this answer




















  • 1





    It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

    – Madhur Bhaiya
    Nov 14 '18 at 9:53












  • This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

    – jPO
    Nov 14 '18 at 9:54











  • Okay^^ I'll change my answer

    – Snowy Heart
    Nov 14 '18 at 9:54











  • This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

    – jPO
    Nov 14 '18 at 10:02















0














I believe that the easier and safer way to do it is to leave the primary key as it is and swap the values of the other columns, should give you the same results






share|improve this answer




















  • 1





    It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

    – Madhur Bhaiya
    Nov 14 '18 at 9:53












  • This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

    – jPO
    Nov 14 '18 at 9:54











  • Okay^^ I'll change my answer

    – Snowy Heart
    Nov 14 '18 at 9:54











  • This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

    – jPO
    Nov 14 '18 at 10:02













0












0








0







I believe that the easier and safer way to do it is to leave the primary key as it is and swap the values of the other columns, should give you the same results






share|improve this answer















I believe that the easier and safer way to do it is to leave the primary key as it is and swap the values of the other columns, should give you the same results







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 9:55

























answered Nov 14 '18 at 9:52









Snowy HeartSnowy Heart

12




12







  • 1





    It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

    – Madhur Bhaiya
    Nov 14 '18 at 9:53












  • This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

    – jPO
    Nov 14 '18 at 9:54











  • Okay^^ I'll change my answer

    – Snowy Heart
    Nov 14 '18 at 9:54











  • This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

    – jPO
    Nov 14 '18 at 10:02












  • 1





    It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

    – Madhur Bhaiya
    Nov 14 '18 at 9:53












  • This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

    – jPO
    Nov 14 '18 at 9:54











  • Okay^^ I'll change my answer

    – Snowy Heart
    Nov 14 '18 at 9:54











  • This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

    – jPO
    Nov 14 '18 at 10:02







1




1





It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

– Madhur Bhaiya
Nov 14 '18 at 9:53






It does not work in newer versions of MySQL. check the comment: stackoverflow.com/questions/2810606/… and that is the whole point of this question.

– Madhur Bhaiya
Nov 14 '18 at 9:53














This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

– jPO
Nov 14 '18 at 9:54





This is not the case. Welcome to the community. If that was the case the error message would state something else not the one I am getting

– jPO
Nov 14 '18 at 9:54













Okay^^ I'll change my answer

– Snowy Heart
Nov 14 '18 at 9:54





Okay^^ I'll change my answer

– Snowy Heart
Nov 14 '18 at 9:54













This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

– jPO
Nov 14 '18 at 10:02





This would work for own tables where I got control over. As the tables I am working with do not belong to me I cannot be sure, that the number of the columns doesn't change. I also would need to count on the fact that there are no other uniques or primaries...

– jPO
Nov 14 '18 at 10:02



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296477%2fswap-primary-keys-in-mysql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20