In your database schema have one column set up to use the
IDENTITY
property
e.g.
create table myTable(
ID int not null IDENTITY(1,1)
)
This will automatically create an ID starting at 1
(1,1)
and incrementing by 1 each time a row is added
(1,1)
. It will automatically handle any rows that are deleted from the table ensuring that the ID is always unique.
See
this link[
^] for the documentation