How to make the primary key set back to zero every time I delete the table contents in a C# program
hi all,
this problem. have c# program running on sql server table. have primary key in table. program intended run many times possible(as in other usual computer programs) user inputs. every time run program needs first read data sql table(lets originaldata table) , math , save results in table called alldata. when run program first time, 600 results , primary key(named id- integer type) starts 1. when run program second time, primary key starts 601 :( need primary key start 1 no matter how many times run program. because need delete first result alldata table(which in program using c# method) , save new results primary key starting one.
i dont want delete whole table , create new table every time run program. want delete previous results , save new results primary key starting @ 1.
here sql dump of the table reference.
use [dataset]
go
/****** object: table [dbo].[alldata] script date: 10/19/2012 14:52:38 ******/
set ansi_nulls on
go
set quoted_identifier on
go
create table [dbo].[alldata](
[id] [int] identity(1,1) not null,
[i] [float] null,
[j] [float] null,
[k] [float] null,
[total] [float] null,
[ratio] [float] null,
[deductions] [float] null,
constraint [pk_dbo.alldata] primary key clustered
(
[id] asc
)with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]
) on [primary]
go
can please suggest way done? highly appreciated.
actually, followed sql table query found in internet create table without understanding sql script much.
thanks,, narada
hi naradasharma,
once delete data in table, can run below query setting id 1.
dbcc checkident (alldata, reseed, 0)
thanks , regards, shailesh b. davara
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment