Doubt in SQL Table

0

I created a table:

Tabela Curso:
Id int auto_increment
nome varchar;

Insert:
Default, Arquitetura;

Architecture has ID 1 in the table.

Deleto the Architecture course.

When I add any other course, it assumes ID = 2.

Is it possible to make it occupy ID = 1, which in theory is vacant?

    
asked by anonymous 30.03.2017 / 17:00

1 answer

1

Gustavo, according to comments, it is not advisable to reuse code in an auto-increment column.

However, if you are faced with a situation where you need to restart or set a new increment value, use the following command:

ALTER TABLE Curso AUTO_INCREMENT = 1;

In this case, the next records entered in the Course table will have the Ids increased from 1.

You can also change the record ID manually with an UPDATE, as commented by Leo Caracciolo.

If the table already has records, I suggest that the auto-increment value defined be the column's MAX + 1, thus avoiding the violation of the uniqueness constraint when inserting the next records.

    
05.04.2017 / 15:43