Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. locking on select

locking on select

Scheduled Pinned Locked Moved Database
helpquestionsharepointdiscussionannouncement
19 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Aadhar Joshi

    you can use lock hints.. update table WITH (TABLOCKX) set status = 1 where keyId = 6 This lock is most safe as well as it increses your performance..

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    He's talking about a SELECT statement, not an UPDATE. No amount of locking is going to speed up reading.

    Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

    A 1 Reply Last reply
    0
    • L Lost User

      He's talking about a SELECT statement, not an UPDATE. No amount of locking is going to speed up reading.

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      A Offline
      A Offline
      Aadhar Joshi
      wrote on last edited by
      #6

      Well it will.. In that case u can use lock hint Select * from TableName WITH (NOLOCK) where 1=1 AND (some condition)

      L 1 Reply Last reply
      0
      • A Aadhar Joshi

        Well it will.. In that case u can use lock hint Select * from TableName WITH (NOLOCK) where 1=1 AND (some condition)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        Any idea what that will do to a database that's not "well designed"? Really think it improves speed? Ever heard of the term "dirty read"?? Stop and THINK for a second - if it were a matter of adding that keyword, wouldn't it be more simple to have the dirty read by default, whether or not the keyword is included?

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        A 1 Reply Last reply
        0
        • L Lost User

          Any idea what that will do to a database that's not "well designed"? Really think it improves speed? Ever heard of the term "dirty read"?? Stop and THINK for a second - if it were a matter of adding that keyword, wouldn't it be more simple to have the dirty read by default, whether or not the keyword is included?

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          A Offline
          A Offline
          Aadhar Joshi
          wrote on last edited by
          #8

          See its fine.. it it would be a draw back, sql shouldnt given it as an option.. Yes there may be dirty read or penthoms but see.. it executes on hard cases where traffic u can find as in mili seconds.. please go through it when it actually creates problem.. Transaction isolation level are used by many companies.. are they fool?? huh.. i myself use read uncommit.. this all are good if u know your architecture..

          L 1 Reply Last reply
          0
          • A Aadhar Joshi

            See its fine.. it it would be a draw back, sql shouldnt given it as an option.. Yes there may be dirty read or penthoms but see.. it executes on hard cases where traffic u can find as in mili seconds.. please go through it when it actually creates problem.. Transaction isolation level are used by many companies.. are they fool?? huh.. i myself use read uncommit.. this all are good if u know your architecture..

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            Aadhar Joshi wrote:

            please go through it when it actually creates problem..

            Ah, sorry, something else ruined my mood - I'm gone.

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            A 1 Reply Last reply
            0
            • L Lost User

              Aadhar Joshi wrote:

              please go through it when it actually creates problem..

              Ah, sorry, something else ruined my mood - I'm gone.

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              A Offline
              A Offline
              Aadhar Joshi
              wrote on last edited by
              #10

              U please read the question.. he is talking about only 100 clients.. u know in a second how many number of locks sql can handle?? every time i don't belive i am good enough for all condition.. same applies to u also..

              L 2 Replies Last reply
              0
              • A Aadhar Joshi

                U please read the question.. he is talking about only 100 clients.. u know in a second how many number of locks sql can handle?? every time i don't belive i am good enough for all condition.. same applies to u also..

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                Aadhar Joshi wrote:

                he is talking about only 100 clients..
                 
                u know in a second how many number of locks sql can handle??

                Yes, I do.

                Aadhar Joshi wrote:

                every time i don't belive i am good enough for all condition.. same applies to u also..

                Making mistakes is the only way I learn; trial and error, and the forum is filled with mistakes I made. Drop the subject and the assumptions, it should not have become this personal. It's just code. Something we do. Now excuse me, the hedonist in me is calling.

                Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                1 Reply Last reply
                0
                • A Aadhar Joshi

                  U please read the question.. he is talking about only 100 clients.. u know in a second how many number of locks sql can handle?? every time i don't belive i am good enough for all condition.. same applies to u also..

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  The reason I dislike the dirty read is because it's not fun if you have to debug a race-condition. Imagine the app being a huge success, and being used in another department with ten times the amount of users. Imagine a simple employee-count being incorrect, because only the employee-record has been inserted, but not yet the contract on which the query joins. Having a consistent and reliable database is "always" more important than having a speedy one. Yes, I'm always this rude, just not that touchy. Got some red wine, some red meat, it's time to relax a bit and have a party. It's good to see a dev with passion, and even better to see one defend his opinion. I hope you're gonna stick around, you'll see I'm not an arse all the time. (Sometimes I'm offline and asleep). FWIW, you'll already have seen this[^] page? That's where you must have found the "cheat" to read before all writes are done. You'll have to assume that most programmers don't use the documentation. If it does not produce any problems with your current architecture, then great - means someone put some extra effort in designing the database. If not, mark it and highlight it and explain what it does with comments in code, as most programmers will not go to MSDN. They'll not even ask here.

                  Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                  A 1 Reply Last reply
                  0
                  • L Lost User

                    The reason I dislike the dirty read is because it's not fun if you have to debug a race-condition. Imagine the app being a huge success, and being used in another department with ten times the amount of users. Imagine a simple employee-count being incorrect, because only the employee-record has been inserted, but not yet the contract on which the query joins. Having a consistent and reliable database is "always" more important than having a speedy one. Yes, I'm always this rude, just not that touchy. Got some red wine, some red meat, it's time to relax a bit and have a party. It's good to see a dev with passion, and even better to see one defend his opinion. I hope you're gonna stick around, you'll see I'm not an arse all the time. (Sometimes I'm offline and asleep). FWIW, you'll already have seen this[^] page? That's where you must have found the "cheat" to read before all writes are done. You'll have to assume that most programmers don't use the documentation. If it does not produce any problems with your current architecture, then great - means someone put some extra effort in designing the database. If not, mark it and highlight it and explain what it does with comments in code, as most programmers will not go to MSDN. They'll not even ask here.

                    Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                    A Offline
                    A Offline
                    Aadhar Joshi
                    wrote on last edited by
                    #13

                    I apologies for what i did.. I know i should listen you first but as u said i am a small kid and i need to go far away.. I can not compete with u, your knowledge, your points but as a senior u should have helping hands.. I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional.. I have to go far away, I hope i get support from u and u help a kid to grow up.. Sorry, Aadhar

                    T L M 3 Replies Last reply
                    0
                    • A Aadhar Joshi

                      I apologies for what i did.. I know i should listen you first but as u said i am a small kid and i need to go far away.. I can not compete with u, your knowledge, your points but as a senior u should have helping hands.. I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional.. I have to go far away, I hope i get support from u and u help a kid to grow up.. Sorry, Aadhar

                      T Offline
                      T Offline
                      The Sql Coder
                      wrote on last edited by
                      #14

                      Good

                      1 Reply Last reply
                      0
                      • A Aadhar Joshi

                        I apologies for what i did.. I know i should listen you first but as u said i am a small kid and i need to go far away.. I can not compete with u, your knowledge, your points but as a senior u should have helping hands.. I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional.. I have to go far away, I hope i get support from u and u help a kid to grow up.. Sorry, Aadhar

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #15

                        Aadhar Joshi wrote:

                        I apologies for what i did..

                        So do I, my apologies for the way I acted.

                        Aadhar Joshi wrote:

                        I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional..

                        We both acted like fools for a few minutes. There's no need to compete; programming is a huge topic, it's impossible to cover all topics.

                        Aadhar Joshi wrote:

                        I have to go far away, I hope i get support from u and u help a kid to grow up..

                        Just stick with your work, it's good to see someone who reads documentation and dares defend his opinion :thumbsup:

                        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                        A 1 Reply Last reply
                        0
                        • L Lost User

                          Aadhar Joshi wrote:

                          I apologies for what i did..

                          So do I, my apologies for the way I acted.

                          Aadhar Joshi wrote:

                          I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional..

                          We both acted like fools for a few minutes. There's no need to compete; programming is a huge topic, it's impossible to cover all topics.

                          Aadhar Joshi wrote:

                          I have to go far away, I hope i get support from u and u help a kid to grow up..

                          Just stick with your work, it's good to see someone who reads documentation and dares defend his opinion :thumbsup:

                          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                          A Offline
                          A Offline
                          Aadhar Joshi
                          wrote on last edited by
                          #16

                          Thanks

                          1 Reply Last reply
                          0
                          • A Aadhar Joshi

                            I apologies for what i did.. I know i should listen you first but as u said i am a small kid and i need to go far away.. I can not compete with u, your knowledge, your points but as a senior u should have helping hands.. I can learn today a big lesson and now i can think i was fool for what i did and totally unprofessional.. I have to go far away, I hope i get support from u and u help a kid to grow up.. Sorry, Aadhar

                            M Offline
                            M Offline
                            Mycroft Holmes
                            wrote on last edited by
                            #17

                            Well good for you! Being able to admit you were wrong is a BIG thing and will make you a better person. Don't let one lousy experience drive you away, stick around and learn we all do that! Oh and we all screw up occasionallyso don't let it stop you from learning.

                            Never underestimate the power of human stupidity RAH

                            1 Reply Last reply
                            0
                            • D dabuskol

                              Hi, I have a SP that calculates data based on criteria, the result were % and duration. It takes 8-10 seconds before it displays the result. The problem is when more users are trying to generate the report, it seems that it takes more time. My problem was when I tried to update a simple statement such as below, it resulted to a "time out expired" and it affects the entire process of the application becuase users cannot perform their task.

                              update table
                              set status = 1
                              where keyId = 6

                              I don't have any locking on my select nor update. What is the best practice to resolve it? I have 100 users nationwide aside from report users, please need help. Thanks in advance Dabuskol

                              Dabsukol

                              K Offline
                              K Offline
                              kankeyan
                              wrote on last edited by
                              #18

                              Locking will not solve your problem. Just optimize your query for better performance. :)

                              1 Reply Last reply
                              0
                              • D dabuskol

                                Hi, I have a SP that calculates data based on criteria, the result were % and duration. It takes 8-10 seconds before it displays the result. The problem is when more users are trying to generate the report, it seems that it takes more time. My problem was when I tried to update a simple statement such as below, it resulted to a "time out expired" and it affects the entire process of the application becuase users cannot perform their task.

                                update table
                                set status = 1
                                where keyId = 6

                                I don't have any locking on my select nor update. What is the best practice to resolve it? I have 100 users nationwide aside from report users, please need help. Thanks in advance Dabuskol

                                Dabsukol

                                H Offline
                                H Offline
                                Hitesh R
                                wrote on last edited by
                                #19

                                One reason would be occurance of deadlock while executing the update query. deadlock occurs at that time you are trying to do multiple operation on the same table at the same time. e.g. select and update both operations are done on same table same time then deadlock will occurs. To avoid this situation use no lock in your select query and use update lock in your update query.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups