How to configure an existing field for auto-increment?

Asked

Viewed 8,462 times

1

I would like to define the field id already created as auto-increment, because I created the table and did not put this option to it, how could I do this?

1 answer

5


To change just use the following command:

For SQL Server:

ALTER TABLE <TABELA>
ALTER COLUMN <Nome_Coluna> Identity (1,1) // caso for sql server

For Mysql:

ALTER TABLE <TABELA>
MODIFY COLUMN <Nome_Coluna> AUTO_INCREMENT // caso for My SQL
  • Haha thanks. But too bad you took so long to answer because I deleted the table and made another with Identity. But I will test yes.

  • It is sql server but the column name is id... How would that look? Oo ALTER TABLE ALTER COLUMN ID Identity (1,1) // if for sql server?

  • 1

    This, however you need to replace TABLE by the name of your table... Arrange and if this field is primary key add PRIMARY KEY at the end.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.