Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete Query Help Require?

Author  Topic 

nickjack
Starting Member

34 Posts

Posted - 2008-11-14 : 02:32:26
Hi
i have a table in which there are 4 columns

ID QuestionNo QuestionName QuestionValue

1 Q001 h1 1
2 Q002 h2 2

Column 2(Question) Get its value from ID and which is auto incremented?
Now if i delete Q002 and insert value then the QuestionNumber comes
Q003 not Q002? Any Help?


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-14 : 02:40:54
that how identity value increments. but why should you be concerned about this? the records will still be in sequence. its just that they will have gaps due to deletion.
If you want them in sequence anyway and if you're using sql 2005, then use row_number() to generate sequence.
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-14 : 02:58:42
no i am working on Sql Server 2000
any sample code?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-14 : 04:22:17
Or use DBCC CHECKIDENT ?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nickjack
Starting Member

34 Posts

Posted - 2008-11-15 : 01:59:05
This is the command to reset the counter? any other solution?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-15 : 04:44:52
quote:
Originally posted by nickjack

This is the command to reset the counter? any other solution?



use a temporary table with identity column. populate it with new records. then add maximum value of identity column from yourtable to each of these records to get new value.
Go to Top of Page
   

- Advertisement -