Re: Long Transaction
From: Roy Alingcastre (RoyAlingcastre_at_discussions.microsoft.com)
Date: 06/12/04
- Next message: AFN: "best way to tune a stored procedure?"
- Previous message: Joe Celko: "Re: Dynamic T-SQL"
- In reply to: Joel: "Re: Long Transaction"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 12 Jun 2004 15:31:01 -0700
Thanks Joel, I like your idea and I'll put it forward. Unfortunately, updates are done by our code, where the statement is dynamically constructed depending on which fields are changed. However if we append the condition you've suggest in the WHERE clause of the UPDATE statement and check for the affected record (should be equal to 1 if success) every update, then we can detect if the update has failed and rollback the transaction.
Roy
"Joel" wrote:
> If you have designed your app such that users can only perform updates by
> stored procs, then there is a farily easy solution.
>
> Create a table called CONFIG with two fields:
>
> CONFIG_ID Varchar(25)
> CONFIG_VALUE Varchar(200)
>
> This is just a generic way of doing the table so that you can store
> unrelated items. Put a record in there with ID='LOCKED' and Value='0'.
> Since it's a character field you can use YES/NO or whatever you want.
>
> At the beginning of your long process update that record to have a value of
> '-1'. At the end of that process change it back to '0'.
>
> In any stored proc that updates one of those tables, put a line like this at
> the top of the proc:
>
> If Exists (Select * from CONFIG Where CONFIG_ID='LOCKED' and
> CONFIG_VALUE='-1')
> Return(1)
>
> You can also use this trick if you have a customized front end. Have your
> edit screens check the value of this record before allowing users to update.
> If the value = locked then set the screen to read-only.
>
> "Roy Alingcastre" <RoyAlingcastre@discussions.microsoft.com> wrote in
> message news:66754594-FCFC-4E11-84BA-AB05B10AE8E4@microsoft.com...
> > Hi,
> >
> > I got a bad feeling about this.....
> >
> > Our application involves around 10 tables in sql server and records in
> them are all interrelated. The application goes through 2 phases, first
> phase is to validate the records in the database, and depending which record
> you start from you could end up going processing all the records stored in
> all the tables. After the first phase all records that have been processed
> should be locked for any updates until the second phase is complete (for big
> system, to complete the whole operation could take hours). However while the
> operation is in progress we still want other users to browse throught the
> records as long as no updates are made.
> >
> > Our brilliant Software Architect recommends to start a big transaction at
> the beginning of phase 1 with isolation level of repeatable read and commit
> at the end of phase2 to guarantee that no processed records are updated
> until the end of this "giant" operation. My concern is, all of the sql
> technical/best practices materials I've read so far discourages you to use
> long transactions and higher isolation level. But our guru said as long as
> we handle blocking and deadlocks gracefully in our application we'll be ok.
> But I still believe that this is a recipe for disaster. Can you suggest any
> other issues that we may not considering aside from blocking and deadlocks.
> > I got a feeling that the database is unusable to other users even just for
> browsing while this giant operation is happening.
> >
> > TIA.
> > Roy
>
>
>
- Next message: AFN: "best way to tune a stored procedure?"
- Previous message: Joe Celko: "Re: Dynamic T-SQL"
- In reply to: Joel: "Re: Long Transaction"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|