Skip to content
Advertisement

How can I generate an ID column for a column in SQL? [closed]

I have a column that I’d like to generate an ID column for. How can I do this using SQL?. Also, is it possible to specify what type of ID I’d like to have as well as length. e.g. letters+ numbers or simply numbers?.

Thank you.

I am using SQL Server and SSMS.

Advertisement

Answer

It has two ways to create primary key in SQL Server:

  1. First in the table like his:
  1. On altering table like:

NB: Only for the number ID column, add IDENTITY(1,1) if you want the number increment automatically like:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement