Archive for May 2008
Resetting the IDENTITY counter in SQL Server T-SQL
You’ve been there before. You are busily testing your import routines and running up the Identity column in your main import table. Before you know it the value is in the multi-millions and you just want to reset it back to 1.
The way to accomplish this is to use the DBCC CHECKIDENT command.
For example:
DBCC CHECKIDENT (SalesForce, reseed, 0)
This assumes your table is called SalesForce and you want to start the numbering at 1. If you wanted to start the number at 2000 you can substitute 0 with 1999. There has been some discussion that has said if the table never had records added to it the reseed value itself will be used instead of the reseed + 1 value. You should not need to use this statement for a “new” table.
Credit for this post is given to Pinal Dave over at http://sqlauthority.com/. The specific post this I am referring to is the one at this page.
Helping block spam with T-SQL
Found a great article on blocking spam using T-SQL code. It is especially useful for blog posts and other community related sites that accept user input. Could even be used on form comments to help block all those guys that submit endless forms on your sites.