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 June 15th, 2005, 03:13 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Identity Column Issue

Hi,
    I have the following problem with the Identity column. Will be glad if someone could help me solve this issue.

Table : Test
Identity Field Name : No1
Field Name : Name1

Initially I insert 5 records so the value in the field No1 is
1
2
3
4
5

Due to errors I delete records where No1 is 4 and 5 so now I have only records where the value of No1 is 1 , 2 and 3.
I insert 2 records afresh. The value assigned to No1 is 6 and 7 but then I want the value to be 4 and 5. Please let me know if this is possible. If yes, how should I be doing this.

Thanks is advance.
 
Old June 15th, 2005, 05:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I dont think this is possible.

_________________________
- Vijay G
Strive for Perfection
 
Old June 16th, 2005, 11:22 AM
Authorized User
 
Join Date: Jun 2003
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

You can use checkident to force the identity value. e.g.

DBCC CHECKIDENT ('table_name', RESEED, new_reseed_value)

You will either need appropriate permissions to run this.

Regards

Nickie
 
Old June 16th, 2005, 12:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

CHECKIDENT will reseed the identity value, but it will not "fill in" the missing values caused by deletions (or INSERTS whose transaction was aborted) which is what the OP was looking for.

There is no way to do this with an identity value.

I can't resist asking why the OP would want to do this. (If I had to guess, this sounds like an attempt to use an identity as a row number, and that is doomed to fail.)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old June 17th, 2005, 09:14 AM
Registered User
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I dont know if this is what you want.

You can have following script to explicitly insert into identity column.So you can fill in the deleted ones.But then the basic purpose of using identity is defeated

SET IDENTITY_INSERT Test ON
INSERT INTO test (No1,Name1) values (1,'test')
SET IDENTITY_INSERT Test OFF

Dont know why you want to do this, but anyways you can work around the above query

Amit
 
Old June 17th, 2005, 03:00 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You can always drop the identity column, as long as it is not involved in a realationship, and then recreate it






Similar Threads
Thread Thread Starter Forum Replies Last Post
Identity Column mike_remember SQL Server 2000 3 July 9th, 2007 07:12 PM
getting identity column from the table g_vamsi_krish SQL Server 2000 1 March 15th, 2006 05:05 PM
identity column rohit_sant SQL Language 4 June 6th, 2005 08:27 AM
Identity column jbenson001 SQL Server 2000 5 April 12th, 2005 02:01 PM





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