Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 April 28th, 2006, 02:53 PM
Authorized User
 
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to al-hijjawi
Default How to reorder the auto number column?

hi every body
i need to reorder the auto number column in sql server 2000
i.e
let we have the column called "Id" and this column is auto numbering
(aka identity)and we have the following values :
1,2,3,4,5,6 if we delete the record which have id=4 the values will be:
1,2,3,5,6 (see the order of number )
i need to reorder this values to be :
1,2,3,4,5

any one help me plz?!!
thank you

 
Old April 28th, 2006, 03:01 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Well, as long as this column in not being used as a FK (foreign key) anywhere, you can manually delete the column and re-add it using the same properties it has now (autonumber, etc). You can also do this via T-SQL as well.

 
Old April 28th, 2006, 03:07 PM
Authorized User
 
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to al-hijjawi
Default

the problem here is this request must be done for a many table some of this table the column id is fk in other tables
but , any way thank you very much and i wish if you can write the t-sql statment which doing that
and thank you agian

 
Old April 28th, 2006, 07:37 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

--First, drop the pk constraint on the original Id column
ALTER TABLE tablename
DROP CONSTRAINT constraintname
GO

ALTER TABLE tablename
DROP COLUMN Id
GO

ALTER TABLE tablename
ADD Id int IDENTITY CONSTRAINT PK_tablename_Id PRIMARY KEY CLUSTERED
GO

Again, i would not recommend this on tables where the PK is being used as a FK to other tables. You are just asking for trouble.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Number query again Brendan Bartley Access 4 August 26th, 2006 06:09 AM
auto generate an number utarian Access 2 March 28th, 2005 02:24 AM
[b]Auto Number[/b] vanjamier Classic ASP Databases 1 November 18th, 2004 03:44 AM
Auto number yami56 Access 1 August 20th, 2004 11:24 AM
Auto number Sheri Dreamweaver (all versions) 0 December 22nd, 2003 03:36 PM





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