Category: Uncategorized

  • Identities and Transactions

    I talked a little recently in a blog about gaps in identity values. They can occur when you delete rows, and the identity process doesn’t “fill in” those gaps or otherwise manage the values to maintain a continuous sequence. Something similar happens with transactions, and it’s a behavior you might not expect.
    If you were do to this:
    CREATE TABLE MyTable
    ( id INT IDENTITY(1,1)
    )
    GO
    INSERT mytable DEFAULT VALUES
    INSERT mytable DEFAULT VALUES
    INSERT mytable DEFAULT VALUES
    INSERT mytable DEFAULT VALUES
    INSERT mytable DEFAULT VALUES

    BEGIN TRANSACTION
    INSERT dbo.MyTable DEFAULT VALUES
    INSERT dbo.MyTable DEFAULT VALUES
    ROLLBACK

    INSERT dbo.MyTable DEFAULT VALUES
    GO
    SELECT * FROM mytable
    GO

    What you get is something you might not expect:

    ident_f
    In the script, 5 values were inserted, then a transaction started and 2 more values were inserted. The transaction was rolled back, so there are still 5 values in the table. We add another one and it gets an 8, not a 6.

    Why not?

    It’s a valid question, and it occurs for this reason. In the code above, the transaction starts and the next row inserts a new value (6) into the table. The identity process now increments it’s “next row” to 7. The next statement runs and it adds a new value (7) and the “next” counter is set to 8. When the rollback occurs, the counter is not changed and so the last INSERT adds a row with a value of 8.
    This seems silly at first until you think about concurrency. Imagine that we run the code above to this point:
    BEGIN TRANSACTION
    INSERT dbo.MyTable DEFAULT VALUES

    Now another user manages to insert a row into the table at this split second. They would actually insert a row with a value of 7, and the second INSERT in this transaction would insert an 8 for it’s value. If the rollback changed the counter, how do we then account for the row with a value of “7” that’s in the table? Inserts from another session are not a part of this transaction.
    Resetting the counter could have drastic implications in a busy environment with lots of connections. It doesn’t make sense, and so this is why a transaction rollback doesn’t reset the identity value. You can try it yourself by running part of this code, then inserting a value in another session before the rollback.
    Once again, the identity property for a table doesn’t manage sequence or gaps, and it is not a part of a transaction rollback. Don’t depend on specific values being set for the identity column in your tables.

  • More Nukes

    One of the reasons that I did not vote for President Obama was his stance on our energy issues, specifically the nuclear power issue. He had listed in his positions that he did not support more nuclear power plants, which I think is a mistake. It’s not a litmus test, but one of the many items I think is important.

    However he recently asked Congress to pass a bill that included a call for more “clean, nuclear power plants. I think that’s great, and it’s something we need to do.

    Having worked in a plant, I appreciate the dangers and issues of waste. However we can, and have, stored waste off for some time at various plants. In addition, I tend to favor above ground, protected, but monitored storage as opposed to putting it under ground and forgetting about it.

    I don’t think we should go completely nuclear, but I think that having more plants, maybe even 1 per state or more, would drastically change the amount of fossil fuels we burn.

    And support a few more computers 🙂

  • I don’t care

    I had meant to check what was up with my Toshiba laptop since I was curious. I gave up last week and ordered a Lenovo after they hadn’t updated the status on my machine. But I was wondering if it was coming back, more as curiosity as to what is going on with their service.

    I shipped it back last Monday, that’s now 6 business days, and they should have had it for 3. The status on my case number is “closed” and there are no notes. I would call, but I’m busy, and this blog post is about all it’s worth.

    Coincidentally, I got a shipment notice today for my Lenovo laptop. I’ll have this one well before the Toshiba is fixed.

  • Reading in 2009

    I saw a blog post from my friend Paul Randal recently in which he recounted the books he’d read in 2009. It’s an impressive list, 100 books, that he compiled in his travels. Paul and his wife, Kimberly, travel a lot, and I think if I were in a similar situation, I’d read 100 books a year as well. However it got me wondering how many I’d read. I’ve tracked them in the past, but since I moved my blog and started using the Kindle and iPhone, I haven’t been doing it. My totals in the past were:

    2008 is also wrong as I got the Kindle in September and started to read on there, forgetting to track books since I was busy and reading quicker on there. I went to my Amazon Kindle account and noticed a few books that are missing, so I’ll need to add those back.
    However.
    This post is about 2009, so in terms of looking over 2009, here’s what I have:

    • 54 ebooks from Amazon
    • 6 ebooks from Barnes and Noble
    • a total of 68 books
    • of the 68, 19 were re-reads
    • 1 classic from the Gutenberg project. I started a second (War and Peace) that has not been completed.

    I don’t have the breakdown of books, though they’re mostly fiction. Of the books I read, I think that a few stood out.
    The Count of Monte Cristo – I grabbed this, along with a few other Gutenberg project books when I first got the Kindle. I struggled with it, and I have to say the first 100 pages barely held my interest. However I plugged away, and eventually really enjoyed this book. The story is amazing and I was surprised how much was happening in there. I ended up really enjoying it.
    The Snowball – I noticed this at the 2007 PASS Summit when Andy Warren and I were walking around the bookstore. He needed books for the ride home, and since I had the kindle I was just keeping him company. I actually made a note and bought this on my way home, starting it then, but finishing it in 2009. I’ve read a lot about Warren Buffet over the years, but this was an amazing look at the guy. Made me realize that not only am I nothing like him, I wouldn’t want to trade places at all.
    Grift Sense – Not sure why I picked this up, but it captivated my interest and I read all the books by James Swain. It deals with cons and casinos, and I loved it. Looking for a similar series from someone else.
    It’s Your Ship: Management Techniques from the Best Damn Ship in the Navy, USS Benfold – This caught my eye in a bookstore and I decided to try it. It’s fantastic, and it shows how someone can really transform a group with good leadership.
    The Clone Republic – I got back into Science Fiction in 2007 with Old Man’s War, which I think is one of the best books I’ve read. This series, which I started on an Amazon recommendation was great as well. Not an all time favorite, but really enjoyable.
    The full list, as best as I can determine, is:

    1. Hear No Evil, James Grippando
    2. Nine Dragons, Michael Connelly
    3. The Night Monster: A Novel of Suspense, James Swain
    4. The Merchant of Death, D.J. MacHale
    5. Pursuit of Honor: A Novel, Vince Flynn
    6. Long Lost, Harlan Coben
    7. The Lost Symbol, Dan Brown
    8. Sucker Bet, James Swain
    9. Midnight Rambler: A Novel of Suspense, James Swain
    10. Deadman’s Bluff: A Novel, James Swain
    11. The Night Stalker: A Novel, James Swain
    12. Dark Watch, Jack Du Brul
    13. Skeleton Coast, Jack Du Brul
    14. The Doomsday Key: A Novel, James Rollins
    15. First Family, David Baldacci
    16. A Plague of Secrets, John Lescroart
    17. Killer Summer (Walt Fleming), Ridley Pearson
    18. Havoc, Jack Du Brul
    19. Finger Lickin’ Fifteen (Stephanie Plum Novels), Janet Evanovich
    20. The Scarecrow, Michael Connelly
    21. Bad Luck and Trouble (Jack Reacher, No. 11), Lee Child
    22. Gone Tomorrow: A Reacher Novel, Lee Child
    23. Cemetery Dance, Douglas Preston and Lincoln Child
    24. Dance of Death, Douglas Preston and Lincoln Child
    25. Wheel of Darkness, Douglas Preston and Lincoln Child
    26. Wicked Prey, John Sandford
    27. Private Wars, Greg Rucka
    28. Walking Dead: A Novel of Suspense, Greg Rucka
    29. Patriot Acts, Greg Rucka
    30. Critical Space, Greg Rucka
    31. The Lost Fleet: Relentless, Jack Campbell
    32. Valiant, Jack Campbell
    33. Courageous, Jack Campbell
    34. Fearless, Jack Campbell
    35. Dauntless,  Jack Campbell
    36. Team of Rivals: The Political Genius of Abraham Lincoln, Doris Kearns Goodwin
    37. To the Nines (Stephanie Plum, No. 9), Janet Evanovich
    38. Ten Big Ones (Stephanie Plum, No. 10), Janet Evanovich
    39. Helfort’s War Book 2: The Battle of the Hammer Worlds, Graham Sharp Paul
    40. The Da Vinci Code: A Novel, Dan Brown
    41. The Clone Alliance, Steven L. Kent
    42. Rogue Clone, Steven L. Kent
    43. Helfort’s War Book 1: The Battle at the Moons of Hell, Graham Sharp Paul
    44. Hard Eight (Stephanie Plum, No. 8), Janet Evanovich
    45. Seven Up (Stephanie Plum, No. 7), Janet Evanovich
    46. Hot Six (Stephanie Plum, No. 6), Janet Evanovich
    47. High Five (Stephanie Plum, No. 5), Janet Evanovich
    48. Four to Score (Stephanie Plum, No. 4), Janet Evanovich
    49. Three Plums In One, Janet Evanovich (three books, #s 1, 2, and 3 of this series)
    50. Fleet of Worlds, Edward M. Lerner
    51. The Clone Republic, Steven L. Kent
    52. Boys Will Be Boys, Jeff Pearlman
    53. The Billionaire Who Wasn’t: How Chuck Feeney Made and Gave Away a Fortune Without Anyone Knowing, Conor O’Clery
    54. Along Came a Spider, James Patterson
    55. Atomic Lobster, Tim Dorsey
    56. The Bodies Left Behind: A Novel, Jeffery Deaver
    57. Teddy Roosevelt, Edd Winfield Parks
    58. The Clone Elite, Steven L. Kent
    59. It’s Your Ship: Management Techniques from the Best Damn Ship in the Navy, USS Benfold, Captain D Abrashoff
    60. The Snowball: Warren Buffett and the Business of Life, Alice Schroeder
    61. Grift Sense (Tony Valentine Series #1), James Swain
    62. Funny Money (Tony Valentine Series #2), James Swain
    63. Deadman’s Poker (Tony Valentine Series #6), James Swain
    64. Sacred Stone (Oregon Files Series #2), Clive Cussler
    65. Mr. Lucky (Tony Valentine Series #5), James Swain
    66. The Count of Monte Cristo, Alexander Dumas

    I started out 2010 with a vacation after New Years and finished 2 books I’d started in 2009 early, plus re-read 4 more since I didn’t have an Internet connection and it was convenient. As of Jan 25, I’ve got 16 books done, but that’s with a week’s vacation.
    It will be interesting to see where 2010 takes me. I’ve started rewriting book reviews on my blog, so I’ll be able to track things.