SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old May 21st, 2004, 06:50 AM
Dieter's Avatar
Dieter Dieter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: SA, Centurion
Posts: 305 Dieter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 26 sec
Reputation Power: 6
How to get the index to start at 0 ??

Hi,

How can I,after deleting all the records in a table, get the index to start at 1 again without having to drop the table and then create it again.

THANKS IN ADVANCE !
__________________
:P

Reply With Quote
  #2  
Old May 21st, 2004, 06:57 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
Quote:
get the index to start at 1 again


Indecies does not start at any number. There must be some misunderstanding.

Reply With Quote
  #3  
Old May 21st, 2004, 07:53 AM
Dieter's Avatar
Dieter Dieter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: SA, Centurion
Posts: 305 Dieter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 26 sec
Reputation Power: 6
sorry my mistake.

I have a table called DD_detail with a column DD_id of int, Identity, Identity Seed = 1, Identity Increment = 1.
and columns DD_type varchar etc....

when I delete all rows from this table, and start to insert again, DD_id starts at the last identity before the table was cleared.
I want it to start at 1 again. How do I do that without dropping the table and then creating it again ??

THANKS

Reply With Quote
  #4  
Old May 21st, 2004, 08:17 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
You can change the identity value by using DBCC but I don't see what the benefit would be.

Reply With Quote
  #5  
Old May 21st, 2004, 08:35 AM
Dieter's Avatar
Dieter Dieter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: SA, Centurion
Posts: 305 Dieter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 26 sec
Reputation Power: 6
I saves me from doing a count everytime I want to see how many records there are in the table.
In mysql you simple run "repair table name" script and wallah, it's done.

Do you understand why I want this now ? Their must be a way.

THANKS

Reply With Quote
  #6  
Old May 21st, 2004, 09:04 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
You cannot assume that the highest identity value in the table is the same as the number of records. If some insert fails there will be a gap for instance.

Reply With Quote
  #7  
Old June 17th, 2004, 11:30 PM
I_LOVE_MAFFLE I_LOVE_MAFFLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 I_LOVE_MAFFLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink

Hi Dieter,

You can actually follow this:
DBCC CHECKIDENT([table name],reseed,0)
-- this will automatically set your identity to 0 again.

I hope it works.

Reply With Quote
  #8  
Old June 18th, 2004, 01:06 AM
Dieter's Avatar
Dieter Dieter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: SA, Centurion
Posts: 305 Dieter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 26 sec
Reputation Power: 6
Thanks a MILLION !!!!!!!!!!!

Finally, it works !!!

THANKS THANKS THANKS THANKS !!!!!!

Reply With Quote
  #9  
Old June 18th, 2004, 10:24 AM
redconfetti redconfetti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Orlando, FL
Posts: 2 redconfetti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to redconfetti
Have problem with that solution.

I try to use that command:

DBCC CHECKIDENT([table name],reseed,0)

Example:
DBCC CHECKIDENT(dbname.tablename, reseed, 0)

I end up getting the error -

"The Query Designer does not support the DBCC SQL construct."

P.S. I'm using SQL Server Standard Edition 8.00.818 (SP3)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > How to get the index to start at 0 ??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway