Search code examples
sqlprimary-keyauto-incrementsql-server-express

SQL Express Alter table add primary key auto increment


I'm trying to alter my table named Vettura to modify field ID and making it both Primary and Auto increment, i have already looked in other answers on other similiar conversation, but i can't find the right answer, can you pls help me?


Solution

  • You might not be able to alter the table this way depending on what data is there and if there are dependencies.

    If you are using SSMS, I would recommend scripting the database to an SQL file including both the schema and the data and setting DROP and CREATE. Then you can edit the table definition(s) and regenerate the database.

    By the way, for SQL-Server, the Auto increment is called IDENTITY.