Lock in SQL Server and Oracle





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I have been doing some tests of locking/blocking in MSSQL Server and Oracle, I noticed one difference:



In Oracle - I performed an update for one row without issuing commit or rollback and in another session I can view the underlying record, of course, I could view the last committed data and not the value that was yet to be committed.



In MSSQL Server - When I did the same operation in another session the SQL Server kept waiting for commit or rollback of the row that is getting updated.



Could somebody please explain locking mechanism between MSSQL server and Oracle.










share|improve this question

























  • Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

    – mustaccio
    57 mins ago






  • 1





    You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

    – EdStevens
    20 mins ago


















1















I have been doing some tests of locking/blocking in MSSQL Server and Oracle, I noticed one difference:



In Oracle - I performed an update for one row without issuing commit or rollback and in another session I can view the underlying record, of course, I could view the last committed data and not the value that was yet to be committed.



In MSSQL Server - When I did the same operation in another session the SQL Server kept waiting for commit or rollback of the row that is getting updated.



Could somebody please explain locking mechanism between MSSQL server and Oracle.










share|improve this question

























  • Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

    – mustaccio
    57 mins ago






  • 1





    You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

    – EdStevens
    20 mins ago














1












1








1








I have been doing some tests of locking/blocking in MSSQL Server and Oracle, I noticed one difference:



In Oracle - I performed an update for one row without issuing commit or rollback and in another session I can view the underlying record, of course, I could view the last committed data and not the value that was yet to be committed.



In MSSQL Server - When I did the same operation in another session the SQL Server kept waiting for commit or rollback of the row that is getting updated.



Could somebody please explain locking mechanism between MSSQL server and Oracle.










share|improve this question
















I have been doing some tests of locking/blocking in MSSQL Server and Oracle, I noticed one difference:



In Oracle - I performed an update for one row without issuing commit or rollback and in another session I can view the underlying record, of course, I could view the last committed data and not the value that was yet to be committed.



In MSSQL Server - When I did the same operation in another session the SQL Server kept waiting for commit or rollback of the row that is getting updated.



Could somebody please explain locking mechanism between MSSQL server and Oracle.







sql-server oracle locking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 20 mins ago









Learning_DBAdmin

742215




742215










asked 1 hour ago









Danilo NetoDanilo Neto

1215




1215













  • Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

    – mustaccio
    57 mins ago






  • 1





    You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

    – EdStevens
    20 mins ago



















  • Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

    – mustaccio
    57 mins ago






  • 1





    You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

    – EdStevens
    20 mins ago

















Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

– mustaccio
57 mins ago





Possible duplicate of Read Committed Snapshot Isolation vs Read Committed - pros and cons?

– mustaccio
57 mins ago




1




1





You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

– EdStevens
20 mins ago





You have hit on one of the fundamental differences between Oracle and MSSQL. In fact I believe this behavior of Oracle is unique to Oracle among all RDBMS products, and many would argue that this is a key reason they consider Oracle to be a superior RDBMS. Instead of trying to make a judgement on how you think it "should" be, or trying to make one behave like the other, it's better to simply adapt best practice for whatever rdbms you are working with. "When in Rome . . . "

– EdStevens
20 mins ago










1 Answer
1






active

oldest

votes


















3














This is a default behavior of SQL server, to understand more you need to invoke isolation level. What you have described above falls in isolation level called "Read Committed". If you want similar behavior like Oracle in SQL server then you need to set the isolation level as Read Committed Snapshot Isolation, basically this isolation level takes snapshot of your data and puts them in tempdb, accordingly you would see last committed record which was snapshot of last committed records. We have another isolation Read Uncommitted, this will also behave like Oracle with a big catch i.e. you would read uncommitted records and there is a fair chance that you could read a dirty record.



There is concept of nolock and readpast as lock hint in SQL server for avoiding locking however it has its own impact.



You may read more about isolation level at Microsoft site at this link.



There are tonnes of article on this subject from many SME, I am listing few of them for your reference:




  1. Brent Ozar --> https://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/


  2. Kendra Little --> https://littlekendra.com/2016/02/18/how-to-choose-rcsi-snapshot-isolation-levels/


  3. Erik Darling --> https://www.brentozar.com/archive/2018/01/heaps-deletes-optimistic-isolation-levels/


  4. Paul White --> https://sqlperformance.com/2014/07/t-sql-queries/isolation-levels


  5. Robert Sheldon --> https://www.red-gate.com/simple-talk/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/



There is a video from Brent Ozar(Unable to find now) where he has clearly explained the difference you have been talking about between Oracle and SQL server. For this reason, Oracle costs much more than SQL server per core.



I hope above helps. Actually this is less of a question than a very important topic and understanding of SQL server and hard to cover them in one answer however above links will definitely guide you in right direction.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f236889%2flock-in-sql-server-and-oracle%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    This is a default behavior of SQL server, to understand more you need to invoke isolation level. What you have described above falls in isolation level called "Read Committed". If you want similar behavior like Oracle in SQL server then you need to set the isolation level as Read Committed Snapshot Isolation, basically this isolation level takes snapshot of your data and puts them in tempdb, accordingly you would see last committed record which was snapshot of last committed records. We have another isolation Read Uncommitted, this will also behave like Oracle with a big catch i.e. you would read uncommitted records and there is a fair chance that you could read a dirty record.



    There is concept of nolock and readpast as lock hint in SQL server for avoiding locking however it has its own impact.



    You may read more about isolation level at Microsoft site at this link.



    There are tonnes of article on this subject from many SME, I am listing few of them for your reference:




    1. Brent Ozar --> https://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/


    2. Kendra Little --> https://littlekendra.com/2016/02/18/how-to-choose-rcsi-snapshot-isolation-levels/


    3. Erik Darling --> https://www.brentozar.com/archive/2018/01/heaps-deletes-optimistic-isolation-levels/


    4. Paul White --> https://sqlperformance.com/2014/07/t-sql-queries/isolation-levels


    5. Robert Sheldon --> https://www.red-gate.com/simple-talk/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/



    There is a video from Brent Ozar(Unable to find now) where he has clearly explained the difference you have been talking about between Oracle and SQL server. For this reason, Oracle costs much more than SQL server per core.



    I hope above helps. Actually this is less of a question than a very important topic and understanding of SQL server and hard to cover them in one answer however above links will definitely guide you in right direction.






    share|improve this answer




























      3














      This is a default behavior of SQL server, to understand more you need to invoke isolation level. What you have described above falls in isolation level called "Read Committed". If you want similar behavior like Oracle in SQL server then you need to set the isolation level as Read Committed Snapshot Isolation, basically this isolation level takes snapshot of your data and puts them in tempdb, accordingly you would see last committed record which was snapshot of last committed records. We have another isolation Read Uncommitted, this will also behave like Oracle with a big catch i.e. you would read uncommitted records and there is a fair chance that you could read a dirty record.



      There is concept of nolock and readpast as lock hint in SQL server for avoiding locking however it has its own impact.



      You may read more about isolation level at Microsoft site at this link.



      There are tonnes of article on this subject from many SME, I am listing few of them for your reference:




      1. Brent Ozar --> https://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/


      2. Kendra Little --> https://littlekendra.com/2016/02/18/how-to-choose-rcsi-snapshot-isolation-levels/


      3. Erik Darling --> https://www.brentozar.com/archive/2018/01/heaps-deletes-optimistic-isolation-levels/


      4. Paul White --> https://sqlperformance.com/2014/07/t-sql-queries/isolation-levels


      5. Robert Sheldon --> https://www.red-gate.com/simple-talk/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/



      There is a video from Brent Ozar(Unable to find now) where he has clearly explained the difference you have been talking about between Oracle and SQL server. For this reason, Oracle costs much more than SQL server per core.



      I hope above helps. Actually this is less of a question than a very important topic and understanding of SQL server and hard to cover them in one answer however above links will definitely guide you in right direction.






      share|improve this answer


























        3












        3








        3







        This is a default behavior of SQL server, to understand more you need to invoke isolation level. What you have described above falls in isolation level called "Read Committed". If you want similar behavior like Oracle in SQL server then you need to set the isolation level as Read Committed Snapshot Isolation, basically this isolation level takes snapshot of your data and puts them in tempdb, accordingly you would see last committed record which was snapshot of last committed records. We have another isolation Read Uncommitted, this will also behave like Oracle with a big catch i.e. you would read uncommitted records and there is a fair chance that you could read a dirty record.



        There is concept of nolock and readpast as lock hint in SQL server for avoiding locking however it has its own impact.



        You may read more about isolation level at Microsoft site at this link.



        There are tonnes of article on this subject from many SME, I am listing few of them for your reference:




        1. Brent Ozar --> https://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/


        2. Kendra Little --> https://littlekendra.com/2016/02/18/how-to-choose-rcsi-snapshot-isolation-levels/


        3. Erik Darling --> https://www.brentozar.com/archive/2018/01/heaps-deletes-optimistic-isolation-levels/


        4. Paul White --> https://sqlperformance.com/2014/07/t-sql-queries/isolation-levels


        5. Robert Sheldon --> https://www.red-gate.com/simple-talk/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/



        There is a video from Brent Ozar(Unable to find now) where he has clearly explained the difference you have been talking about between Oracle and SQL server. For this reason, Oracle costs much more than SQL server per core.



        I hope above helps. Actually this is less of a question than a very important topic and understanding of SQL server and hard to cover them in one answer however above links will definitely guide you in right direction.






        share|improve this answer













        This is a default behavior of SQL server, to understand more you need to invoke isolation level. What you have described above falls in isolation level called "Read Committed". If you want similar behavior like Oracle in SQL server then you need to set the isolation level as Read Committed Snapshot Isolation, basically this isolation level takes snapshot of your data and puts them in tempdb, accordingly you would see last committed record which was snapshot of last committed records. We have another isolation Read Uncommitted, this will also behave like Oracle with a big catch i.e. you would read uncommitted records and there is a fair chance that you could read a dirty record.



        There is concept of nolock and readpast as lock hint in SQL server for avoiding locking however it has its own impact.



        You may read more about isolation level at Microsoft site at this link.



        There are tonnes of article on this subject from many SME, I am listing few of them for your reference:




        1. Brent Ozar --> https://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/


        2. Kendra Little --> https://littlekendra.com/2016/02/18/how-to-choose-rcsi-snapshot-isolation-levels/


        3. Erik Darling --> https://www.brentozar.com/archive/2018/01/heaps-deletes-optimistic-isolation-levels/


        4. Paul White --> https://sqlperformance.com/2014/07/t-sql-queries/isolation-levels


        5. Robert Sheldon --> https://www.red-gate.com/simple-talk/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/



        There is a video from Brent Ozar(Unable to find now) where he has clearly explained the difference you have been talking about between Oracle and SQL server. For this reason, Oracle costs much more than SQL server per core.



        I hope above helps. Actually this is less of a question than a very important topic and understanding of SQL server and hard to cover them in one answer however above links will definitely guide you in right direction.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 49 mins ago









        Learning_DBAdminLearning_DBAdmin

        742215




        742215






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f236889%2flock-in-sql-server-and-oracle%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown