Dinesh G
Dinesh G

Reputation: 242

How to update sno ascending order in mysql?

I just want to update my column auto increment ascending order no

and my table structure is:

------------
sno   | name 
------------
yyyy  |  gff
------------
xxxx  |  gch
------------
oouu  |  ghc
------------
ghfd  |  hvh
------------

I want the result must be:

------------
sno   | name 
------------
1  |  gff
------------
2  |  gch
------------
3  |  ghc
------------
4  |  hvh
------------

I tried the following code

 UPDATE table SET AUTO_INCREMENT(no)

I know this is wrong. Actually i mentioned this for example. Please help me to solve this code.

Upvotes: 0

Views: 275

Answers (1)

Sadikhasan
Sadikhasan

Reputation: 18600

You have to follow this three steps of query

ALTER TABLE table_name DROP PRIMARY KEY;
ALTER TABLE table_name ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
ALTER TABLE table_name DROP COLUMN sno ;

Upvotes: 1

Related Questions