I must be getting tired... Once again I almost damaged my blog trying to get a pristine local copy. This time I decided that it would be easiest to export the blog as BlogML and reload it into the local web application. However I didn't notice that when I first exported the blog, it generated an error (I think due to the "Embed Attachments" option) in the export so I regenerated the export without embedded attachments. When I went to import the BlogML, somehow I didn't notice that it was connected to my real blog and not my local blog (like I said it is getting late!) and imported a duplicate of the information I had already created. At least this time I was able to cover my tracks without incident. Here is the SQL I used to clean up the database:
-- I determined the last valid entry was ID = 34
-- so I removed entries after 34 and reseeded the
-- identity column.
DELETE subtext_Links
WHERE PostID IN (
SELECT ID
FROM subtext_Content
WHERE ID > 34
)
GO
DELETE subtext_Feedback
WHERE EntryID IN (
SELECT ID
FROM subtext_Content
WHERE ID > 34
)
GO
DELETE subtext_Content
WHERE ID > 34
GO
DBCC CHECKIDENT ('dbo.subtext_Content', RESEED, 34)
GO
I had to recheck the documentation on CHECKIDENT just to make sure that I should use the maximum value (34) and not the next value (35). According to the documentation:
Current identity value is set to the new_reseed_value. If no rows have been inserted to the table since it was created, the first row inserted after you run DBCC CHECKIDENT uses new_reseed_value as the identity. Otherwise, the next row inserted uses new_reseed_value + the current increment value.