Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

mysql - If I delete a row from a table in a database how to rename the primary keys

So I want to delete a row from a table e.g

1

2

3

4

5

7

8

How do I rename the tables rows primary keys so they are equal to

1

2

3

4

5

6

7

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This question comes frequently but it's a false problem. You don't have to care about id. It's just an identifier. Leave it as it is.

You can add a progressive number programmatically, using your favourite programming language or via sql.

select *,@row:=@row+1 as progressive_number
from table, (select @row:=0) as t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...