locking a table?

Results 1 to 2 of 2

Thread: locking a table?

  1. #1
    Join Date
    Dec 1969

    Default locking a table?

    hi, i have a field thats not a autonumber but is the primary key,and every time a record is to be inserted in that table i got to select the previous max. number increment it by one and insert the new record.the problem is if two persons simulteneously access the record and try to insert at the same time then both will have a same digit (eg:last record has id as 100 then these two guys will access 100 incriment it to 101 and try to insert indvidually but there will be a duplicacy of primary key and the application will throw an error).what i want is as soon as one gets the record no other person should be able to access that table or record.what sort of locking will help me out. iam trying out with pessimestic locking.Plz help.

  2. #2
    Join Date
    Dec 1969

    Default Stored Procedure?

    Could you use a SQL Stored Procedure to actually perform the complete task?<BR>So instead of asking the database what the highest ID is and then you adding 1 to it and the create a new record - The SP could do the whole job of creating a complete new record with the next ID and then inserting the rest of the values that you pass.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts