Welcome to Thycotic Development Blogs Sign in | Join | Help

Different results when reseeding in SQL Server

Discovered the other day that reseeding in SQL Server gets different results based on whether the table has ever had data in it.  This is regardless of whether all the data in the table has been deleted or not.  Copy the following SQL code into Query Analyzer and see for your self...

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[WeirdIdentityReseedProblem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 drop table [dbo].[WeirdIdentityReseedProblem]
GO

CREATE TABLE [dbo].[WeirdIdentityReseedProblem] (
 [Id] [int] IDENTITY (1, 1) NOT NULL ,
 [AnotherField] [varchar] (255) NULL
) ON [PRIMARY]
GO

--#2 Now just execute here on down...
DELETE FROM WeirdIdentityReseedProblem
DBCC CHECKIDENT ('[dbo].[WeirdIdentityReseedProblem]' , RESEED, 0)
insert into WeirdIdentityReseedProblem (AnotherField) values('FirstValue')
insert into WeirdIdentityReseedProblem (AnotherField) values('SecondValue')
insert into WeirdIdentityReseedProblem (AnotherField) values('ThirdValue')
--select * from WeirdIdentityReseedProblem
DECLARE @FirstId INT

select @FirstId = Id from WeirdIdentityReseedProblem where AnotherField = 'FirstValue'
Print 'Value of Id of first record: ' + CAST(@FirstId AS VARCHAR(30))

You'll always get 0 as the reseed value.  Executing from #2 on down will always return 1.

Replace #2 on down with...

IF EXISTS (SELECT 1 FROM WeirdIdentityReseedProblem)                 
BEGIN
    DBCC CHECKIDENT ('[dbo].[WeirdIdentityReseedProblem]' , RESEED, 0)
END
DELETE FROM WeirdIdentityReseedProblem
insert into WeirdIdentityReseedProblem (AnotherField) values('FirstValue')
insert into WeirdIdentityReseedProblem (AnotherField) values('SecondValue')
insert into WeirdIdentityReseedProblem (AnotherField) values('ThirdValue')
--select * from WeirdIdentityReseedProblem
DECLARE @FirstId INT

select @FirstId = Id from WeirdIdentityReseedProblem where AnotherField = 'FirstValue'
Print 'Value of Id of first record: ' + CAST(@FirstId AS VARCHAR(30))

Now whether you execute the whole text or from #2 on down you get 1.  Unfortunately, if the table is empty, it doesn't work.  Since we practice TDD at Thycotic, we always reset the database before each unit test.  If our unit test leaves the table empty we're hosed.  FYI- the first portion of the SQL would be in a different file and is for demonstration only.

Plug the following just after #2 and this will break it...

DELETE FROM WeirdIdentityReseedProblem

Anybody got any suggestions? 


 

 

 

Posted by bryant.smith | 0 Comments

MCP x 2 now.

Passed the 70-316 (C# Desktop) exam last week!  Woohoo!!!  One more to go!

Posted by bryant.smith | 0 Comments

Recapping 2005...Kristines Party

Wow!  I've really been negligent on my blogging.  A few months ago I blogged about a friend that had a party promoting her business as a personal organizer...  so...  She has been a big help to me personally and everybody I met at the party seemed to have come to the same conclusion.  It was fun, well organized, and while it was about her business, the business portion (a speech) lasted maybe 10 minutes.  Plus, a portion of that 10 minutes was giving gifts away.  If anybody needs help organizing their home or business in the DC area, drop me a note and I'll introduce you to Kristine.

Posted by bryant.smith | 0 Comments

Recapping 2005...Became a MCP

In August I passed 70-315 (Web Apps in C#)  Wahoo!  I'm currently studying for 70-316 (Desktop Apps in C#), and will be taking the test on January 3rd.
Posted by bryant.smith | 0 Comments

Recapping 2005...Joing Thycotic

First and foremost the best thing that happened in 2005 is joining Thycotic Software.  It definitely the best job that I've ever had.  Still getting used to being a consultant and not having my own desk, but that's ok.  I am also grateful for my coworkers, they're both very cool and fun to program with when we get to pair up, which is often.  We have great clients too, and actually got invited to a holiday party by one of them, where I made off with a nice poker chip set.  I have to confess that I was nervous taking the job at Thycotic.  I am normally very conservative when it comes to making career decisions.  Things that run through my mind are, building tenure, working for large companies, and having routine that doesn't change much.  These are just some of the things that would have normally kept me from leaving ADP.  But, as fate would have it, a good friend convince me to leave for another large company (which shall go nameless) with the intention/hope of going agile.  Six months later, after working 60-70 hour weeks, a long commute, a few gray hairs, and no signs of going agile...  The man upstairs (I'm a christian, so I have to give my props!) had me primed, desperate, and ready for a change.  And now seven plus months, tons of unit test, and thousands of assertions later...  I'm doing TDD, pair programming, and all that is agile.  Well, not all, but it's close!

 

Posted by bryant.smith | 0 Comments

If your in the DC area, friend's party celebrating new business!

A friend, who happens to be my personal organizer, is having a party this Saturday, October 8th.  Though she is using it to network, it is just a party.  No presentations!  Just fine food, dessert, beer & wine, etc.  She will be giving out prizes and there will be documentation / handouts available. 

While Kristine's intention is to be low key as far as her organizing business this Saturday, I don't have to be in this blog.  Kristine is great, and has done wonders over the last couple of months.  She has been very flexible, therefore not stuck in doing things her way!  I've have had experiences w/others who are not so flexible.  Plus, she has learned from me and has passed the knowledge on to her other clients.

7pm, Saturday, October 8th ...  Organize University!, 9300 Colesville Road, Silver Spring, MD

Directions: 495 to Exit 30B, toward Silver Spring, 1st right onto St. Andrews Way, large tudor home on the corner.

Bryant

Posted by bryant.smith | 0 Comments

Declare Your Independence the DIP!

Sorry for the long delay!  I have had best man duties and the possibility of having to move hanging over my head!  I'm excited to get the opportunity get my first post out tonight.

I was reflecting on last week's events especially the 4th of July.  I was invited to see the fireworks on top of Dept. of Interior.  It had a terrific view of the fireworks and the monuments, except for the Lincoln Memorial.

In light of that I am posting a few articles, and a presentation of mine, on the Dependency Inversion Principle. They all directly or indirectly related to the DIP, and being that I was thinking of the 4th, and needed something to blog about…

 Here are some links that I hope to be blogging about over the next month or so:

 http://authors.aspalliance.com/thycotic/articles/view.aspx?id=5      Article by Thycotic!

 http://www.netobjectives.com/streamzines/CurrentStreamzine/       An excellent media tutorial on Commonality-Variability Analysis

 http://thycotic.com/data/downloads/dip_ocp_agile.zip                  A presentation I did last year for our local XP user’s group in Washington, DC.

Bryant

Posted by bryant.smith | 0 Comments