What is the practical used of nolock in sql server -
i going around document in msdn , said "no shared locks issued prevent other transactions modifying data read current transaction".
so in lay man term(i.e mine) cause problem of dirty read. dangerous, if why used it?
does knows practical scenario used.
in our case (previous job) used getting ballpark numbers. example table holds millions of e-mails sent in given day, if @ 5:00 want see "where are" can say:
select count(*) dbo.messagetable (nolock) campaignid = x , customerid = y; a lot of people suggest using count(*) no where clause. argue if you're willing accept inaccuracy in count(*) may do:
select sum(rows) sys.partitions [object_id] = object_id('dbo.tablename') , index_id in (0,1); this number inaccurate due in-flight transactions, doesn't have scan table, far more efficient. our case use subsets: filtered index in place (for other purposes) query sys.partitions use index_id of filtered index.
in cases, though, using nolock may feel turbo button, inaccuracy may cause worth it. unless system heavily tempdb-bound, should consider read_committed_snapshot current nolock scenarios instead. see pros , cons of read_committed_snapshot
Comments
Post a Comment