<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Reseed Identity of Table &#8211; Table Missing Identity Values &#8211; Gap in Identity Column</title>
	<atom:link href="http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Fri, 20 Nov 2009 20:17:18 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mahesh Nair</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-57485</link>
		<dc:creator>Mahesh Nair</dc:creator>
		<pubDate>Tue, 10 Nov 2009 10:51:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-57485</guid>
		<description>My humble experience of past few years (as a Sr.System Analyst &amp; DB Architect) support the comments by Mr.IrishManInUSA also I support  Mr.Ed McInerney. 
I believe Mr. Pinal was just conveying about such a method. 
The application of this thing may vary depends on situation. Anyway it&#039;s very useful for a table with a dedicated column for customizable sort order, rather than the concept of primary key resorting.</description>
		<content:encoded><![CDATA[<p>My humble experience of past few years (as a Sr.System Analyst &amp; DB Architect) support the comments by Mr.IrishManInUSA also I support  Mr.Ed McInerney.<br />
I believe Mr. Pinal was just conveying about such a method.<br />
The application of this thing may vary depends on situation. Anyway it&#8217;s very useful for a table with a dedicated column for customizable sort order, rather than the concept of primary key resorting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: harish</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-55220</link>
		<dc:creator>harish</dc:creator>
		<pubDate>Wed, 26 Aug 2009 05:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-55220</guid>
		<description>Hi pinal,

thank you 

thank you very much




Thanks &amp; regrads

Harishkumar.M</description>
		<content:encoded><![CDATA[<p>Hi pinal,</p>
<p>thank you </p>
<p>thank you very much</p>
<p>Thanks &amp; regrads</p>
<p>Harishkumar.M</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed McInerney</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-54417</link>
		<dc:creator>Ed McInerney</dc:creator>
		<pubDate>Tue, 04 Aug 2009 12:08:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-54417</guid>
		<description>Some of the critics here are forgetting about inherited code and data (not OO inheritence, hand-me-down code).

I just inherited a DB table that contains an ID column and an order number column that was not originally an Identity column. So, all records are unique on the ID PK column, but *should* also be unique on the order number as well...they are NOT.

Some records have a NULL order number and some order numbers are duplicated. The difficulty is in making the decisions of how to rectify these issues:

Can we delete the data if it is older? That is simple.

If not, how to make this an Identity column and still retain the existing order numbers for historical purposes? SQL Server 2005 doesn&#039;t let you make an existing column IDENTITY: &quot;You cannot modify an existing table column to add the IDENTITY property.&quot;

How to find gaps (un-used numbers) around the same date range of the records with NULL or duplicate order numbers to try to use those to fix the bad records...we could simply use the next highest order number, but the users intuitively know the approximate date of the orders based on the order number and this would throw them off.

If anyone has suggestions for these real-world issues, I&#039;d be interested in hearing them.</description>
		<content:encoded><![CDATA[<p>Some of the critics here are forgetting about inherited code and data (not OO inheritence, hand-me-down code).</p>
<p>I just inherited a DB table that contains an ID column and an order number column that was not originally an Identity column. So, all records are unique on the ID PK column, but *should* also be unique on the order number as well&#8230;they are NOT.</p>
<p>Some records have a NULL order number and some order numbers are duplicated. The difficulty is in making the decisions of how to rectify these issues:</p>
<p>Can we delete the data if it is older? That is simple.</p>
<p>If not, how to make this an Identity column and still retain the existing order numbers for historical purposes? SQL Server 2005 doesn&#8217;t let you make an existing column IDENTITY: &#8220;You cannot modify an existing table column to add the IDENTITY property.&#8221;</p>
<p>How to find gaps (un-used numbers) around the same date range of the records with NULL or duplicate order numbers to try to use those to fix the bad records&#8230;we could simply use the next highest order number, but the users intuitively know the approximate date of the orders based on the order number and this would throw them off.</p>
<p>If anyone has suggestions for these real-world issues, I&#8217;d be interested in hearing them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Drew Wells</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-53435</link>
		<dc:creator>Drew Wells</dc:creator>
		<pubDate>Thu, 02 Jul 2009 20:07:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-53435</guid>
		<description>We are having an issue with the identify column of one of our normalized tables.  The primary key (identity) of TableA is referenced by TableB and TableC.  

When we went to move this table from one database to another, the identity column was reseeded.  This of course caused havoc with our data since records were being paired incorrectly.

Is there a way around this?</description>
		<content:encoded><![CDATA[<p>We are having an issue with the identify column of one of our normalized tables.  The primary key (identity) of TableA is referenced by TableB and TableC.  </p>
<p>When we went to move this table from one database to another, the identity column was reseeded.  This of course caused havoc with our data since records were being paired incorrectly.</p>
<p>Is there a way around this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yasmin</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-53353</link>
		<dc:creator>Yasmin</dc:creator>
		<pubDate>Tue, 30 Jun 2009 11:55:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-53353</guid>
		<description>Hi All,

In the above example, the identity missing was found by manually. Is there any way to find the same using SQL statement ?

ie, How we can find the list of tables whose identity was missed(not is sequential order) within the entire database?</description>
		<content:encoded><![CDATA[<p>Hi All,</p>
<p>In the above example, the identity missing was found by manually. Is there any way to find the same using SQL statement ?</p>
<p>ie, How we can find the list of tables whose identity was missed(not is sequential order) within the entire database?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Puneet</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-51909</link>
		<dc:creator>Puneet</dc:creator>
		<pubDate>Fri, 15 May 2009 06:18:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-51909</guid>
		<description>Dear Syyed, 

Can you kindly elaborate your solution about triggers</description>
		<content:encoded><![CDATA[<p>Dear Syyed, </p>
<p>Can you kindly elaborate your solution about triggers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Syyed</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-51849</link>
		<dc:creator>Syyed</dc:creator>
		<pubDate>Wed, 13 May 2009 22:50:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-51849</guid>
		<description>IrishManInUSA is 100% right</description>
		<content:encoded><![CDATA[<p>IrishManInUSA is 100% right</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Syyed</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-51848</link>
		<dc:creator>Syyed</dc:creator>
		<pubDate>Wed, 13 May 2009 22:47:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-51848</guid>
		<description>hi Vinit,

use the updated trigger on the table and get the result in sequence.

like 1,2,3,4,5,6,7
no 1,2,3,5,7,10</description>
		<content:encoded><![CDATA[<p>hi Vinit,</p>
<p>use the updated trigger on the table and get the result in sequence.</p>
<p>like 1,2,3,4,5,6,7<br />
no 1,2,3,5,7,10</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anand srivastava</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-51265</link>
		<dc:creator>anand srivastava</dc:creator>
		<pubDate>Fri, 24 Apr 2009 11:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-51265</guid>
		<description>I fully agree with IrishManInUSA the basic purpose of id column is defeated if we rearrange the sequence of id. The Id is unique identity given to a row its not a serial no.
(though in the article this is meant to be )</description>
		<content:encoded><![CDATA[<p>I fully agree with IrishManInUSA the basic purpose of id column is defeated if we rearrange the sequence of id. The Id is unique identity given to a row its not a serial no.<br />
(though in the article this is meant to be )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RCN</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50484</link>
		<dc:creator>RCN</dc:creator>
		<pubDate>Sat, 04 Apr 2009 13:50:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50484</guid>
		<description>People that need to do this are not understanding the right way to do this.  You don&#039;t need consecutive IDs, you only need UNIQUE IDs.

IF you need consecutive IDs, create a VIEW that simply ORDERS the table with consecutive IDs.

Trust me, you don&#039;t need consecutive IDs in the TABLE.</description>
		<content:encoded><![CDATA[<p>People that need to do this are not understanding the right way to do this.  You don&#8217;t need consecutive IDs, you only need UNIQUE IDs.</p>
<p>IF you need consecutive IDs, create a VIEW that simply ORDERS the table with consecutive IDs.</p>
<p>Trust me, you don&#8217;t need consecutive IDs in the TABLE.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IrishManInUSA</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50435</link>
		<dc:creator>IrishManInUSA</dc:creator>
		<pubDate>Thu, 02 Apr 2009 23:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50435</guid>
		<description>Kind of funny how we make assumptions on the design and not fully understanding why the junior developer did what they did.

Without actually knowing what they were doing, kind of hard to say it was a design flaw, I think the whole point of the article was how to reindex identity column so that they are in sequence.

Now if had been something I worked, then I would not care what is in the id column, I would have a second column that would be seen by the user.

i.e. patient number, product sku, the id column would be something that could use to build a relationship lookup or nothing at all. Again depending on the design.

Nice article, but I am sure that the author pointed out how to get around it and then probably asked the developer why they were doing that and point him/her in the right direction. :)</description>
		<content:encoded><![CDATA[<p>Kind of funny how we make assumptions on the design and not fully understanding why the junior developer did what they did.</p>
<p>Without actually knowing what they were doing, kind of hard to say it was a design flaw, I think the whole point of the article was how to reindex identity column so that they are in sequence.</p>
<p>Now if had been something I worked, then I would not care what is in the id column, I would have a second column that would be seen by the user.</p>
<p>i.e. patient number, product sku, the id column would be something that could use to build a relationship lookup or nothing at all. Again depending on the design.</p>
<p>Nice article, but I am sure that the author pointed out how to get around it and then probably asked the developer why they were doing that and point him/her in the right direction. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lee Dumond</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50407</link>
		<dc:creator>Lee Dumond</dc:creator>
		<pubDate>Thu, 02 Apr 2009 06:46:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50407</guid>
		<description>I agree with Anthony. As long as the values are unique, it should not matter what they are. If a solution relies on an uninterrupted sequence of identity values, then the solution is poorly designed.

IMHO, any solution that uses integers as identity values should also be able to use GUIDs without any loss of basic functionality. If you can&#039;t do that, you need to rethink what you&#039;re doing.</description>
		<content:encoded><![CDATA[<p>I agree with Anthony. As long as the values are unique, it should not matter what they are. If a solution relies on an uninterrupted sequence of identity values, then the solution is poorly designed.</p>
<p>IMHO, any solution that uses integers as identity values should also be able to use GUIDs without any loss of basic functionality. If you can&#8217;t do that, you need to rethink what you&#8217;re doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50398</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Thu, 02 Apr 2009 05:50:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50398</guid>
		<description>ID column should have no business meaning so it doesn&#039;t matter if it skips 1, 2 or a 1000 values. It just needs to uniquely identify a row (or entity).</description>
		<content:encoded><![CDATA[<p>ID column should have no business meaning so it doesn&#8217;t matter if it skips 1, 2 or a 1000 values. It just needs to uniquely identify a row (or entity).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Grace</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50396</link>
		<dc:creator>Anthony Grace</dc:creator>
		<pubDate>Thu, 02 Apr 2009 05:02:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50396</guid>
		<description>If he is relying on the uninterrupted order of the keys, then that is a design flaw.</description>
		<content:encoded><![CDATA[<p>If he is relying on the uninterrupted order of the keys, then that is a design flaw.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Too much in a number</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50342</link>
		<dc:creator>Too much in a number</dc:creator>
		<pubDate>Wed, 01 Apr 2009 09:15:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50342</guid>
		<description>Why do people put so much meaning in the order of number, if it is an identity, it should just be unqiue, doesn&#039;t matter in the order.

if the order matters, generate it at run time!</description>
		<content:encoded><![CDATA[<p>Why do people put so much meaning in the order of number, if it is an identity, it should just be unqiue, doesn&#8217;t matter in the order.</p>
<p>if the order matters, generate it at run time!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinit</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comment-50330</link>
		<dc:creator>Vinit</dc:creator>
		<pubDate>Wed, 01 Apr 2009 05:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195#comment-50330</guid>
		<description>Hi Pinal,
I&#039;m wondering if we have records like 1,2,3,5,6,8,9... then what? So here is the revised version of the above SQL statements which will insert into middle and at bottom.

CREATE TABLE TableID (ID INT IDENTITY(1,1), Col VARCHAR(10))
GO
/* Insert 10 records with first value */
INSERT INTO TableID (Col)
VALUES (&#039;First&#039;)
GO 10
/* Check the records in table */
SELECT *
FROM TableID
GO
/* Delete records from middle and bottom both*/
DELETE
FROM TableID
WHERE ID IN (4,7,11,12)
Go
/* Check the records in table */
SELECT *
FROM TableID
GO
/*	
	Now check the missing identity values 
	To Do so we will create a memory table with a sequential number, 
	from 1 to the ident_current value and join that to the live table.
*/
Declare @rows Int
Declare @numberOfRowsToInsert Int

declare @seq table (
   seq int not null primary key
)
/* Get current Max Value and reseed table */
SELECT @rows = MAX(ID) FROM TableID
DBCC CHECKIDENT(&#039;TableID&#039;, RESEED, @rows)
set @rows = (select Ident_Current(&#039;TableID&#039;)) + 5
/* Insert values into Memory table */
declare @i int
set @i = 1
while @i &lt;= @rows
begin
   insert @seq values( @i )
   set @i = @i + 1
end
/* Now set the Identity Insert On, so that we can insert any number */
Set Identity_Insert TableID On

INSERT INTO TableID(Id,col) Select seq,&#039;Third&#039;
From @seq left outer join TableID T on seq = T.ID
Where T.ID Is Null

Set Identity_Insert TableID OFF
/* Check the records in table */
SELECT *
FROM TableID
GO
/* Clean Database */
DROP TABLE TableID
GO

-Vinit</description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
I&#8217;m wondering if we have records like 1,2,3,5,6,8,9&#8230; then what? So here is the revised version of the above SQL statements which will insert into middle and at bottom.</p>
<p>CREATE TABLE TableID (ID INT IDENTITY(1,1), Col VARCHAR(10))<br />
GO<br />
/* Insert 10 records with first value */<br />
INSERT INTO TableID (Col)<br />
VALUES (&#8216;First&#8217;)<br />
GO 10<br />
/* Check the records in table */<br />
SELECT *<br />
FROM TableID<br />
GO<br />
/* Delete records from middle and bottom both*/<br />
DELETE<br />
FROM TableID<br />
WHERE ID IN (4,7,11,12)<br />
Go<br />
/* Check the records in table */<br />
SELECT *<br />
FROM TableID<br />
GO<br />
/*<br />
	Now check the missing identity values<br />
	To Do so we will create a memory table with a sequential number,<br />
	from 1 to the ident_current value and join that to the live table.<br />
*/<br />
Declare @rows Int<br />
Declare @numberOfRowsToInsert Int</p>
<p>declare @seq table (<br />
   seq int not null primary key<br />
)<br />
/* Get current Max Value and reseed table */<br />
SELECT @rows = MAX(ID) FROM TableID<br />
DBCC CHECKIDENT(&#8216;TableID&#8217;, RESEED, @rows)<br />
set @rows = (select Ident_Current(&#8216;TableID&#8217;)) + 5<br />
/* Insert values into Memory table */<br />
declare @i int<br />
set @i = 1<br />
while @i &lt;= @rows<br />
begin<br />
   insert @seq values( @i )<br />
   set @i = @i + 1<br />
end<br />
/* Now set the Identity Insert On, so that we can insert any number */<br />
Set Identity_Insert TableID On</p>
<p>INSERT INTO TableID(Id,col) Select seq,&#8217;Third&#8217;<br />
From @seq left outer join TableID T on seq = T.ID<br />
Where T.ID Is Null</p>
<p>Set Identity_Insert TableID OFF<br />
/* Check the records in table */<br />
SELECT *<br />
FROM TableID<br />
GO<br />
/* Clean Database */<br />
DROP TABLE TableID<br />
GO</p>
<p>-Vinit</p>
]]></content:encoded>
	</item>
</channel>
</rss>
