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


VulpesRank #55 · 29.2K reputationPosted Mar 24, 2014, 4:22 AM EDT
deletedIds.Sort();
Note that the above code will reuse the lowest deleted ID first regardless of the order in which records were deleted.
Munesh SharmaRank #174 · 13.9K reputationPosted Mar 23, 2014, 9:48 PM EDT
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 23, 2014, 10:38 PM EDT
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.
Abolfazl155 reputationPosted Mar 24, 2014, 12:53 AM EDT