Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

missing sql rows

Options
  • 03-11-2006 11:24pm
    #1
    Registered Users Posts: 1,002 ✭✭✭


    I am testing a script that inserts data into a sql DB. Sometimes it works - sometimes it doesn't (not a problem, I'm testing!)

    When the script fails no records are add to the database. Then the script succeeds a record gets added. But I end up missing many rows, for example the last successful row could be id= 5 then it jumps to id=9.

    Where do the missing rows go if nothing gets added to the DB? :rolleyes:


Comments

  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    It's almost impossible to guess without more details.

    It could be a flaw in your logic, but without seeing the script, it is hard to say.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Precisely. This is impossible to diagnose without the script your using.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Tis a very simple thing really

    When you are using SQL Server and the Auto increment property on an ID field, when you prepare to insert it takes the next availible number. If the insert fails it wont be reused. So when the next insert happens it takes the next one etc etc

    So for example say you have 1 success 3 fails 1 success starting at ID 1

    1 - Success
    2 - Fail
    3- Fail
    4- Fail
    5- Success

    So your table no has numbers 1 & 5 in the db...

    You can reseed it but its a standard part of SQL Server


  • Registered Users Posts: 1,002 ✭✭✭MargeS


    Txs Ginger - so the ID is reserved before the insert happens! Maybe generating random userID's is a better way to go.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Not really.. just leave it as is .. less work and you know the numbers will be unique..

    @SESSION_IDENTITY)

    No real need to worry about it


  • Advertisement
Advertisement