Click here to Skip to main content
15,891,567 members
Home / Discussions / Database
   

Database

 
GeneralBackup of SQL Server Pin
leckey25-Feb-08 10:09
leckey25-Feb-08 10:09 
GeneralRe: Backup of SQL Server Pin
Hesham Amin25-Feb-08 21:15
Hesham Amin25-Feb-08 21:15 
Questionembeddd query Pin
baranils25-Feb-08 8:22
baranils25-Feb-08 8:22 
GeneralRe: embeddd query Pin
Krish - KP25-Feb-08 16:33
Krish - KP25-Feb-08 16:33 
GeneralSimple admin question for user logins Pin
Leo Smith25-Feb-08 8:20
Leo Smith25-Feb-08 8:20 
GeneralRe: Simple admin question for user logins Pin
Krish - KP25-Feb-08 16:22
Krish - KP25-Feb-08 16:22 
GeneralSQL record locking (to prevent other READS?) Pin
BungleBonce25-Feb-08 5:57
BungleBonce25-Feb-08 5:57 
GeneralRe: SQL record locking (to prevent other READS?) Pin
andyharman25-Feb-08 7:51
professionalandyharman25-Feb-08 7:51 
I normally do something like this:
create procedure dbo.GetNextAvailable
as begin
  declare @id int
  set nocount on

  --Start transaction so that locking works.
  begin tran

  --Get Id of next record to process.  The "holdlock" hint tells SQL
  --Server to place a lock on the row until the end of the transaction.
  --The "readpast" hint tells SQL-Server to ignore a record if it is
  --locked by one of your other two processes. Note that this only works
  --for "read committed" isolation.
  select top 1 @id = MyId from MyTable with (holdlock, readpast)
    where status = 'READY'
    order by MyId

  --Mark the record as "in-progress" so that no-one else can pick-up
  --the current record.
  update MyTable set status = 'IN PROGRESS'
    where MyId = @id
    and status = 'READY'

  --Complete the transaction.
  commit trans

  --Return the record to the front-end for processing.  If no records
  --returned then there are no records left to process.
  select * from MyTable where MyId = @id

  return(0)
end
You could potentially move the transaction outside of the stored procedure. I normally update the status to "SUCCESS" or "FAILURE" after I have completed processing of the record. If the record processing is substantial then I normally also maintain start and end times for each record.

Regards
Andy
GeneralRe: SQL record locking (to prevent other READS?) Pin
BungleBonce26-Feb-08 0:38
BungleBonce26-Feb-08 0:38 
GeneralRe: SQL record locking (to prevent other READS?) Pin
andyharman26-Feb-08 4:32
professionalandyharman26-Feb-08 4:32 
Generalautomatic stored procedure or trigger Pin
Mogaambo25-Feb-08 2:55
Mogaambo25-Feb-08 2:55 
GeneralRe: automatic stored procedure or trigger Pin
DoomedOne25-Feb-08 3:46
DoomedOne25-Feb-08 3:46 
GeneralRe: automatic stored procedure or trigger Pin
Mogaambo25-Feb-08 4:28
Mogaambo25-Feb-08 4:28 
GeneralRe: automatic stored procedure or trigger Pin
DoomedOne25-Feb-08 5:54
DoomedOne25-Feb-08 5:54 
QuestionMS Access permissions issue...? Pin
ChandraRam25-Feb-08 1:11
ChandraRam25-Feb-08 1:11 
AnswerRe: MS Access permissions issue...? Pin
Krish - KP25-Feb-08 16:44
Krish - KP25-Feb-08 16:44 
GeneralRe: MS Access permissions issue...? Pin
ChandraRam25-Feb-08 17:55
ChandraRam25-Feb-08 17:55 
GeneralSQL 2005 Login Issue [modified] Pin
Brady Kelly25-Feb-08 0:37
Brady Kelly25-Feb-08 0:37 
GeneralRe: SQL 2005 Login Issue Pin
User 27100925-Feb-08 0:50
User 27100925-Feb-08 0:50 
GeneralRe: SQL 2005 Login Issue Pin
Jacquers25-Feb-08 0:53
Jacquers25-Feb-08 0:53 
GeneralOT: SQL 2005 Login Issue Pin
RichardGrimmer25-Feb-08 1:22
RichardGrimmer25-Feb-08 1:22 
GeneralRe: OT: SQL 2005 Login Issue Pin
Brady Kelly25-Feb-08 1:40
Brady Kelly25-Feb-08 1:40 
QuestionHow to get the varbinary value from SQLServer2005 and display that string in WebForm? Pin
Tamizh24-Feb-08 23:14
Tamizh24-Feb-08 23:14 
QuestionRe: How to get the varbinary value from SQLServer2005 and display that string in WebForm? Pin
pmarfleet25-Feb-08 2:10
pmarfleet25-Feb-08 2:10 
Questiontable datatype in sp sql server Pin
Sonia Gupta24-Feb-08 23:04
Sonia Gupta24-Feb-08 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.