Hi,
Here is a structure of my table
create table events
(
event_id integer primary key identity(1,1),
event_name varchar(200),
event_date datetime,
)
Note: The event_id is a automacally and we don't need to insert record in this field.
for example
i have inserted 10 records in a table
then i deleted all records manually from sql server
but when again I save the record the event_id field shows started from 11 even the table was empty,
although it should be start from 1?
11 was saved on the table for the next Id to be used.
|||So how I manage this records becuase I want to start from 1 if I have deleted from database.
|||That is proper. The only way to start back at 1 would be to reindex your DB. The Identity prperty will always give a "unique" number that hasnt been assigned before.
Hope this helps
Tim
|||Well, Tim Could you please explain me that how I can reindex automatically this table I am using asp.net
|||Actually now that i think about it, an even easy solution would be to just drop and recreate the table after you have deleted the records:
Just right click on the table on SQL server Object explorer and go to Script Table as --> Create to --> New Query Editor Window. This will give you the script to create the table exactly as you haven ow if you dont already ahve it then simply in a script do the following:
DROP TABLE 'TableName'
Paste CREATE TABLE script here
GO
May I ask why you need th eindex to start over after you delete records? Are you using the ID's somewhere else?
Tim
|||Actually I am doing a Project thats why I am asking anyway I solved my Problem Thanks a lot
Cheers!
No comments:
Post a Comment