|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 PM
Points: 1,227,
Visits: 1,356
|
|
palotaiarpad (12/19/2012) I'm also wrong, but i learned something. Could someone please explain, why is the identity resetted after a truncate? For me is a possible source of inconsitency.
TRUNCATE command apart from removing data from the table, resets the seed value of the identity column defined in the table.
Another command to re-seed identity is DBCC CHECKIDENT. It can be used something like below:
DBCC CHECKIDENT ('test_trun', RESEED, 0)
~ Lokesh Vij
Guidelines for quicker answers on T-SQL question Guidelines for answers on Performance questions
Link to my Blog Post --> www.SQLPathy.com
Follow me @Twitter

|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 PM
Points: 1,227,
Visits: 1,356
|
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Thursday, June 13, 2013 9:46 AM
Points: 3,157,
Visits: 4,341
|
|
Good back-to-basics question, Thanks
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 1,127,
Visits: 1,274
|
|
bcoz it is its behavior that every time we execute TRUNCATE command it will reset the identity value..
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Today @ 6:18 AM
Points: 691,
Visits: 1,104
|
|
| Thanks for a nice easy Wednesday question.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:50 PM
Points: 5,289,
Visits: 7,219
|
|
palotaiarpad (12/19/2012) Could someone please explain, why is the identity resetted after a truncate? Because conceptually, TRUNCATE TABLE is closer to DROP / CREATE than to DELETE.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, May 29, 2013 10:36 PM
Points: 773,
Visits: 464
|
|
Easy one.. Remembering basics...
-- Dineshbabu Desire to learn new things..
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:53 PM
Points: 7,179,
Visits: 7,276
|
|
SQL Kiwi (12/19/2012)
Another good one. 19% wrong right now  Yes, a good one. And in the last 6 hours the wrong rate has grown from 19% to 27%, which seems rather high for such an easy question.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, May 30, 2013 4:47 AM
Points: 106,
Visits: 354
|
|
palotaiarpad (12/19/2012) why is the identity resetted after a truncate? For me is a possible source of inconsitency.
As Lokesh has already explained, resetting the identity seed is a characteristic of the 'truncate' command. If you want to retain the seed then you use 'delete' instead. So, there's no inconsistency, it is just a case of using the right command according to your needs.
At least you learnt something, so from that point of view it is a good question.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 8:24 AM
Points: 1,526,
Visits: 1,561
|
|
palotaiarpad (12/19/2012) I'm also wrong, but i learned something. Could someone please explain, why is the identity resetted after a truncate? For me is a possible source of inconsitency.
Hello, if resetting the identity is a possible source of inconsistency you may try using DELETE instead of TRUNCATE. DELETE will remove the data without resetting the identity.
|
|
|
|