Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Isolation levels are really about how long shared locks on data being read are kept. But as Lieven already mention: those are <strong>NOT</strong> about preventing "corruption" in the database - those are about preventing readers and writers from getting in each other's way.</p> <p>First up: any write operation (<code>INSERT</code>, <code>UPDATE</code>) will <strong>always</strong> require an <strong>exclusive</strong> lock on that row, and exclusive locks are not compatible with anything else - so if a given row to be updated is already locked, any <code>UPDATE</code> operation will have to wait - no way around this.</p> <p>For <strong>reading data</strong>, SQL Server takes out <strong>shared locks</strong> - and the isolation levels are about how long those are held.</p> <p>The <strong>default</strong> isolation level (<code>READ COMMITTED</code>) means: SQL Server will try to get a shared lock on a row, and if successful, read the contents of the row and release that lock again right away. So the lock only exists just for the brief period of the row being read. Shared locks are compatible to other shared locks, so any number of readers can read the same rows at the same time. Shared locks however prevent exclusive locks, so shared locks prevent mostly <code>UPDATE</code> on the same rows.</p> <p>And then there's also the <code>READ UNCOMMITTED</code> isolation level - which basically takes out no locks; this means, it can also read rows that are currently being updated and exclusively locked - so you might get non-committed data - data that might not even really end up in the database in the end (if the transaction updating it gets rolled back) - be careful with this one!</p> <p>The next level up is <code>REPEATABLE READ</code>, in which case the shared locks once acquired are held until the current transaction terminates. This locks more rows and for a longer period of time - reads are repeatable since those rows you have read are locked against updates "behind your back".</p> <p>And the ultimate level is <code>SERIALIZABLE</code> in which entire ranges for rows (defined by your <code>WHERE</code> clause in the <code>SELECT</code>) are locked until the current transaction terminates.</p> <p><strong>Update:</strong></p> <blockquote> <p><em>More than the download part (secondary for me) I am worried about 5 users trying to update one database at the same time.</em></p> </blockquote> <p>Well, don't worry - SQL Server will <strong>definitely</strong> handle this without any trouble!</p> <p>If those 5 (or even 50) concurrent users are updating different rows - they won't even notice someone else is around. The updates will happen, no data will be hurt in the process - all is well.</p> <p>If some of those users try to update the <strong>same row</strong> - they will be serialized. The first one will be able to get the exclusive lock on the row, do its update, release the lock and then go on. Now the second user would get its chance at it - get the exclusive lock, update the data, release lock, go on.</p> <p>Of course: if you <strong>don't do anything about it</strong>, the second user's data will simply overwrite the first update. That's why there is a need for concurrency checks. You should check to see whether or not the data has changed between the time you read it and the time you want to write it; if it's changed, it means someone else already updated it in the mean time -> you need to think of a concurrency conflict resolution strategy for this case (but that's a whole other question in itself....)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload