{"id":8082,"date":"2015-06-29T15:10:17","date_gmt":"2015-06-29T15:10:17","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/locking-objects-in-sql-source-control\/"},"modified":"2016-07-28T10:56:43","modified_gmt":"2016-07-28T10:56:43","slug":"locking-objects-in-sql-source-control","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/other\/locking-objects-in-sql-source-control\/","title":{"rendered":"Locking objects in SQL Source Control"},"content":{"rendered":"<div>\n<p>The beta of SQL Lock has now been retired and Redgate have rolled the object locking feature into the SSMS plug-in SQL Source Control. Read more about object locking in SQL Source Control <a href=\"http:\/\/www.red-gate.com\/blog\/object-locking?utm_source=simpletalk&amp;utm_medium=publink&amp;utm_campaign=sqlsourcecontrol&amp;utm_content=soclocking\">here<\/a>.<\/p>\n<\/p><\/div>\n<p>If you share a database with other developers, chances are you&#8217;ve encountered a situation like this:<\/p>\n<p>1. Alice starts editing an object.<\/p>\n<p>2. Meanwhile, not realizing Alice is working on the object, Bob unwittingly edits and saves the same object.<\/p>\n<p>3. Alice, not realizing Bob was working on the same thing, saves her changes.<\/p>\n<p>Presto: Bob&#8217;s work is gone. And what&#8217;s more, Bob and Alice might not even notice. The error could make it all the way to production. We spoke to one developer who lost a week&#8217;s work when their database was deployed without critical changes that had been accidentally overwritten.<\/p>\n<p>We have some experience solving this problem. In 2013, we released <a href=\"https:\/\/www.red-gate.com\/products\/oracle-development\/source-control-for-oracle\/\">Source Control for Oracle 2<\/a>, with a feature to let users lock objects on Oracle databases so other people can&#8217;t edit them. After that, we released a free beta of SQL Lock, an add-in for Management Studio that does the same job for SQL Server. Now we&#8217;re retiring SQL Lock and rolling the feature into <a href=\"http:\/\/www.red-gate.com\/products\/sql-development\/sql-source-control\">SQL Source Control<\/a>.<\/p>\n<p>The feature is simple. When you want to work on an object, you right-click it in the Object Explorer and select <b>Lock this object<\/b>.<\/p>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2015\/06\/lock-this-object.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6708 aligncenter\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2015\/06\/lock-this-object.png\" width=\"445\" height=\"308\" alt=\"lock-this-object.png\" \/><\/a><\/p>\n<p>After you lock it, the object is marked with a padlock icon in the Object Explorer. If other people try to save changes to the object, they&#8217;ll see an error explaining that it&#8217;s locked by you.<\/p>\n<p>Of course, if you take a vacation or get hit by a bus, your team&#8217;s going to need to work on your locked objects without you. For that reason, we let anyone unlock objects, even if they didn&#8217;t lock it themselves. We see the feature not as a way to protect your changes but to stop people stepping on your toes.<\/p>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2015\/06\/Locking-tab1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6707 aligncenter\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2015\/06\/Locking-tab1.png\" width=\"767\" height=\"248\" alt=\"Locking-tab1.png\" \/><\/a><\/p>\n<p>All the locking is done on the server, so it works independently of your source control system.<\/p>\n<p>You can try object locking out by installing SQL Source Control 4 on <a href=\"http:\/\/documentation.red-gate.com\/display\/SOC3\/Turning+on+Frequent+Updates\">Frequent Updates<\/a>. When SQL Source Control 4 is released on our main release channel, we&#8217;ll remove the feature from SQL Source Control 3 &#8211; so try it now, while it&#8217;s hot!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The beta of SQL Lock has now been retired and Redgate have rolled the object locking feature into the SSMS plug-in SQL Source Control. Read more about object locking in SQL Source Control here. If you share a database with other developers, chances are you&#8217;ve encountered a situation like this: 1. Alice starts editing an&#8230;&hellip;<\/p>\n","protected":false},"author":94407,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-8082","post","type-post","status-publish","format-standard","hentry","category-other"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/8082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/94407"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=8082"}],"version-history":[{"count":9,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/8082\/revisions"}],"predecessor-version":[{"id":42497,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/8082\/revisions\/42497"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=8082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=8082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=8082"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=8082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}