|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, July 31, 2007 8:20 AM
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"
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 17, 2010 1:57 AM
Points: 18,
Visits: 48
|
|
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 ?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 7:19 AM
Points: 2,023,
Visits: 5,971
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 17, 2010 1:57 AM
Points: 18,
Visits: 48
|
|
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.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, March 19, 2010 2:04 AM
Points: 1,725,
Visits: 2,366
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 17, 2010 1:57 AM
Points: 18,
Visits: 48
|
|
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 ?
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, March 19, 2010 2:04 AM
Points: 1,725,
Visits: 2,366
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 17, 2010 1:57 AM
Points: 18,
Visits: 48
|
|
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...
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, March 19, 2010 2:04 AM
Points: 1,725,
Visits: 2,366
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 17, 2010 1:57 AM
Points: 18,
Visits: 48
|
|
Thanks for Support and answering my Question.
i got the solution for the Order by in sub Query ok thanks.
|
|
|
|