The query to create the table with its respective field set as IDENTITY is the following:
CREATE TABLE user (
email varchar(100) primary key
name varchar(30),
pwd varchar(10)
)
Alter table to add IDENTITY field:
ALTER TABLE user ADD id int /*NOT NULL*/ IDENTITY;
The email
field to be PRIMARY KEY INDEX will fail if a NULL or DUPLICATED value was set, for example supposed that myemail@domain.com
already exists, OK the query fails, but I change the email to anotheremail@domain.com
SQL Server generate a new one value for the IDENTITY field based on the query(s) that failed before. My question is why does this happen? (Is this ONLY on SQL Server or other database providers also)