If you want to quickly remove all rows from a table and begin the table from scratch TRUNCATE is the best approach. It is quicker too since it logs nothing (so beware).
TRUNCATE is only for destroying all data in a table though. What if you want to remove only the last few rows and then begin the seeding off from the last primary key?
Use CHECKIDENT to reseed
You can delete the rows you want and after you can reset the SEED of the table to what you desire using the following line:DBCC CHECKIDENT('myTable', RESEED, 10)
Note: the 10 is a seed so you would set this to be the current maximum identity. So if you reseed with 10 the next insert will yield 11 as the primary key.
Hope this helps someone:
ReplyDelete-- Get the seed in case of rollback.
SELECT @tbl_Seed = (MAX(ID)) FROM [tbl]
-- Do stuff...
-- Upon rollback
IF NOT @tbl_Seed IS NULL BEGIN
PRINT ''
PRINT 'Reseeding [tbl] to original identity seed...'
DBCC CHECKIDENT ('[tbl]', RESEED, @tbl_Seed);
END
تركيب جبس بورد بالرياض تركيب جبس بورد بالرياض
ReplyDeleteمعلم دهانات بالرياض معلم دهانات بالرياض
ارخص نقل اثاث بجدة ارخص نقل اثاث بجدة
فني تركيب ورق جدران بالرياض فني تركيب ورق جدران بالرياض
نقل عفش من الدمام الى الاردن نقل عفش من الدمام الى الاردن
There are many religious research paper services and Religion Assignment Writing Services to choose from for those stuck with their religion & theology essay services and theology & religion writing services.
ReplyDeleteList with all The Sims 4 cheats. Max out Skills, Get Promoted on your Career, Money Cheats, Death/Kill Cheats, Emotion Cheats, List with all Cheat Codes.
ReplyDeleteExcellent read, Positive site, where did u come up with the information on this posting? I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work,If anyone interested similar one's have a look here thanks.
ReplyDeleteshih tzu puppies for sale near me
buy puppy online
fuhrerschein-kaufen-schweiz