How to renumber table IDs in MySQL? [duplicate]

0

I deleted the sales records from my sales table, and canceled sales, from my sales table. So the sales numbering got messy, like: it starts with 9, 10, 11, 14 .... How do I sort sales from # 1 and so on?

    
asked by anonymous 07.01.2015 / 17:15

2 answers

2

Another solution to the scenario presented, ONLY if there are no relationships in this table:

SET @contador = 0;
UPDATE 'tabela_vendas' SET 'tabela_vendas'.'id' = @contador := @contador + 1;

Source: #

After this, run the command below, setting again the initial number of auto_imcrement to 0:

ALTER TABLE tabela_vendas AUTO_INCREMENT = 0
    
07.01.2015 / 18:21
1

I think you want to reshape AUTO_INCREMENT . Try:

ALTER TABLE sua_tabela AUTO_INCREMENT = 0
    
07.01.2015 / 17:31