Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2005, 08:55 PM
Authorized User
 
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default Who can help me !


 I have a table Ex: Students
 with Primary key is StudentID
it automatical increase values when I insert new one

but When I delete One . The value of StudentID will be hole

and Now I want to Compact all the Hole values when I delete

How to to this ?

thanks you in advanced !

 
Old September 28th, 2005, 11:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

wht do u mean by "The value of StudentID will be hole"

and "I want to Compact all the Hole values"



 
Old September 28th, 2005, 11:20 PM
Authorized User
 
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ex:
StudentID LastName
1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
9 I
10 J


When I Execute query "Delete from student where studentid=4"

then My Table will be

StudentID LastName
1 A
2 B
3 C

5 E
6 F
7 G
8 H
9 I
10 J

The value 4 will be hole

and now I want my Table become

StudentID LastName
1 A
2 B
3 C

4 E
5 F
6 G
7 H
8 I
9 J




 
Old September 29th, 2005, 01:33 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you don't mind me asking: Why would you want to do something like that? It does not make any sense. What about the potential links from other tables to the studentid? The studentid would become meaningless...

Gert

 
Old September 29th, 2005, 08:22 PM
Authorized User
 
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes ! i see

but now i want my table like that . Can you help me

 
Old September 29th, 2005, 08:51 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you use an identity value, you have to reset the identify value after you reshift everything. My suggestion is select the data into another table of the same structure. Let the new table reassign new key values, the drop the old table, recreated the old table in the proper name, then select all the data back once again so you can preserve the table name. But I agree with the person above why would you want to do that? Perhaps a better idea would to be to not use an identity value?

 
Old September 29th, 2005, 11:28 PM
Authorized User
 
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes !

you want to know what's my goal .I would like my table like this because on my site i want to create a web site pagging able . but i dont like creat #temp table and then insert data into

because it take a long time to execute.

 
Old September 30th, 2005, 11:39 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can't you just write a "paging" stored procedure to retrieve the data but leave the data the way it is in the database with the gaps? I think this would be much quicker. Anytime you change the key value of your table to remove the duplicates you also have to change all the values of the other tables foreign keyed to this table that your changing. This creates A cascading change nightmare.










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.