hi
i have a table with a column set to primary key and is identify as yes.when i delete a record from table, primary key field deleted but primary key steel start from where old data has primary key.for example a record with primary key set to 1,i delete it but new record primary key set to 2.
i need to set it automatically to 1.
i use linq to sql for connect to database and i don't know sql server commands.i want to set it with linq to sql and c#.
thanks

VulpesPosted Mar 24, 2014, 8:22 AM
deletedIds.Sort();
Note that the above code will reuse the lowest deleted ID first regardless of the order in which records were deleted.
AbolfazlPosted Mar 24, 2014, 4:53 AM
Jignesh TrivediPosted Mar 24, 2014, 2:38 AM
hi,
This is normal behavior of Identity column. It will skip the value whenever you delete data from database or sql statement fail to insert new record.
Please refer
http://technet.microsoft.com/en-us/library/aa933196(v=sql.80).aspx
hope this will help you.
Munesh SharmaPosted Mar 24, 2014, 1:48 AM
create table tablename
{
id primary key IDENTITY(INT,1,2)
name varchar(50)
}
IDENTITY(INT,1,2) here IDENTITY means it will start from 1 and take gap b/w id 2