devxlogo

Auto assigning primary key values

Auto assigning primary key values

Question:
Is there a way to have SQL Server assign values to key fields automatically, so that every time a new record is added it just increases the prior record’s key by one?

Answer:
Yes, you can either use the Identity function (you need to create a column in your table that uses Identity as its datatype) or you can create your own surrogate key generator.

devx-admin

Share the Post: