Transaction isolation and reading from multiple tables on SQL Server Express and SQL Server 2005

可紊 提交于 2019-12-05 22:10:33

Your choice of loading all data in one go means very few options:

  • Use sp_getapplock to serialise access through the relevant code
  • Use TABLOCKX, HOLDLOCK on the reads in a transaction

You have issues because SET TRANSACTION ISOLATION LEVEL SERIALIZABLE only affects isolation of the locks: you need to control duration (HOLDLOCK) and granularity + mode (TABLOCKX)

I sometimes get inconsistent results,

Unless you will later on do batch processing on a database that is otherwise not used, better get used to certain fluctuations which WILL NOT MATTER ANYWAY.

Unless you have very few entries the changes wont matter in absolute numbers. You deal with statistics anyway. Use READ COMMITED and deal with the inconsitencies by accepting that the data set is not static.

Anything else will totally kill perforamnce.

OR go batch processing.

Alternatively: use a SNAPSHOT to seal a "view in time" of the database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!