Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Reset Identity Columns for Tables Using Them


Reset Identity Columns for Tables Using Them

Author
Message
ckempste
ckempste
SSC Eights!
SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)

Group: General Forum Members
Points: 885 Visits: 1
Comments posted to this topic are about the item Reset Identity Columns for Tables Using Them


Chris Kempster
www.chriskempster.com
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"
kuldipMCA
kuldipMCA
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 144
but what about current data in the Table

what we do for this data ?

any solution because we set primary key for the identity column
so what happned for that thing ?
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5689 Visits: 25280
For a full understanding of the DBCC CHECKIDENT command read Books On Line (BOL) at:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/2c00ee51-2062-4e47-8b19-d90f524c6427.htm

paying particular attention to what might happed if you use the command improperly ...
If the table is not empty, setting the identity value to a number less than the maximum value in the identity column can result in one of the following conditions:

If a PRIMARY KEY or UNIQUE constraint exists on the identity column, error message 2627 will be generated on later insert operations into the table because the generated identity value will conflict with existing values.


If a PRIMARY KEY or UNIQUE constraint does not exist, later insert operations will result in duplicate identity values.


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
kuldipMCA
kuldipMCA
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 144
That's right but then
what is the use of the set indentity ?

if we set it to max no value in the table.

so there no change in the table after or before this command.
ps.
ps.
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2257 Visits: 3668
kuldip.bhatt (1/20/2009)
That's right but then
what is the use of the set indentity ?

if we set it to max no value in the table.

so there no change in the table after or before this command.




are you referring to SET IDENTITY_INSERT ON? This is used to explicitly insert a specific value in the identity column.

Also what are you reffering to max value in the table? The max value is determined by the capacity of underlying datatype used for the identity column. If you use bigint instead of int, you can have more number of identity values.



Pradeep Singh
kuldipMCA
kuldipMCA
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 144
I know Indentity_Insert = On .

my questiion is

Suppose there is one table and it has one primary key it's type is Integer.

currrenlty this table has 20 rows but it's last indentity value is 60.

then i use this dbcc command or not use it will be insert the next row

at 61 am right or wrong ?

then what is the use of this DBCC COmmand that i my Question ?
ps.
ps.
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2257 Visits: 3668
kuldip.bhatt (1/20/2009)
my questiion is

Suppose there is one table and it has one primary key it's type is Integer.

currrenlty this table has 20 rows but it's last indentity value is 60.

then i use this dbcc command or not use it will be insert the next row

at 61 am right or wrong ?

then what is the use of this DBCC COmmand that i my Question ?


Yes it'll get the value 61 (if the increment is set to 1).
You can use dbcc to find the current identity value and current column value and reseed the current identity value to a new value of your choice or need.

In your case, assuming the identity column has gaps (say 20,21,22,23) and you fire DBCC checkident('mytable', reseed, 20), the next time you try to insert any row in the table, it'll start with 21

Pls go through the following test...

create table #t
(
col1 bigint identity(1,1),
col2 varchar(10)
)

-- run the below query 6 times
insert into #t(col2)
select 'a'
union all
select 'a'
union all
select 'a'
union all
select 'a'

delete from #t where col1 between 20 and 25

dbcc checkident("#t")

--output
Checking identity information: current identity value '29', current column value '29'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

-- now reseeding the identity column
dbcc checkident("#t",reseed,20)

--output
Checking identity information: current identity value '29', current column value '20'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

-- again start inserting into the table
it'll start from 21..... and will create duplicates if there are existing values.

Hope this clarifies...



Pradeep Singh
kuldipMCA
kuldipMCA
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 144
Thanks I understand what u said ok

so if Primary key then there no solution for the DBCC COmmand

but you can insert duplicate value in the table.

One more Question it that i had some problem

facing

i can't use Order by in Sub Query.

is there any mechansium that i use order by desc and top in the sub Query

if u know then tell me...
ps.
ps.
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2257 Visits: 3668
kuldip.bhatt (1/20/2009)

so if Primary key then there no solution for the DBCC COmmand
I dont think i understood what you mean here...

i can't use Order by in Sub Query.

is there any mechansium that i use order by desc and top in the sub Query


You can use both ORDER BY and TOP in a sub query. You can also use only TOP in the subquery. You cannot use only ORDER BY in a subquery.
Quoting from BOL
When ORDER BY is used in the definition of a view, inline function, derived table, or subquery, the clause is used only to determine the rows returned by the TOP clause. The ORDER BY clause does not guarantee ordered results when these constructs are queried, unless ORDER BY is also specified in the query itself.




Pradeep Singh
kuldipMCA
kuldipMCA
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 144
Thanks for Support and answering my Question.

i got the solution for the Order by in sub Query ok thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search