Hey guys, I created an ID table with Auto Increment, checking the table I saw that Bugou, has any command in SQL that reorders from the value 1,2,3,4 to the last one? just for the sake of reorganization. Thank you.
As discussed in the comments, you should not worry about this aesthetic question of the identifier but about the integrity of the data.
In the scenario where this Primary Key
is not Foreign Key
of any other value or even value to another weak reference. You can store the current contents of the table, perform a truncate, and repopulate it again.
/* Criando a estrutura de armazenamento sem o ID */
DECLARE @TabelaTemporaria TABLE(
Status VARCHAR(50)
/* restante das suas colunas */
)
/* Armazenando o conteúdo existente na [SUA_TABELA] para a @TabelaTemporaria */
INSERT INTO @TabelaTemporaria ([Status] /* restante das suas colunas */)
(SELECT Status /* demais campos sem o Id */FROM [SUA_TABELA])
/* Limpando a [SUA_TABELA] */
TRUNCATE TABLE [SUA_TABELA]
/* Populando novamente a tabela original */
INSERT INTO [SUA_TABELA] (idSistema)
(SELECT * FROM @TabelaTemporaria)