PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] How do you change the primary key, when rows have the same value?

 January 23, 2022     mysql, phpmyadmin     No comments   

Issue

I added a new row to my Payable table named id (int 5) and want to change the primary key from stock (int 5) to id. However when I created the id row sql inserted a 0 value for each row. How do I alter the table, giving each row an auto incremented value starting at 10001 and make that the primary key?


Solution

Something like this (since MySQL allows in-line assignments):

SET @var = 10000;
UPDATE Payable
SET id = (@var := @var + 1);

SQL Fiddle



Answered By - PM 77-1
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing