Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sduffy77
Starting Member
18 Posts |
Posted - 2009-03-13 : 10:20:52
|
| hello All, What is the best practice for keeping a page view count in sql.Currently:We have a field named [viewcount] in the page table.I am doing an update in the sproc that gets the page record where it sets the viewcount = viewcount + 1.However the issue comes where if multiple users try to view the same page at the same time, we get deadlocks.Is there a better way that I can be doing this? |
|
|
heavymind
Posting Yak Master
115 Posts |
Posted - 2009-03-13 : 10:30:23
|
| you can do something like select @a = id from page with (updlock)where id = @aorudpate pageset viewcount = viewcountwhere id = @ato aquire a lock in the beginning. thus you will have only locking w/o deadlocksIf this does not work out - show us the deadlock graphThanks, VadymMCITP DBA 2005/2008Chief DBA at http://www.db-staff.com |
 |
|
|
sduffy77
Starting Member
18 Posts |
Posted - 2009-03-13 : 12:13:38
|
quote: Originally posted by heavymind you can do something like select @a = id from page with (updlock)where id = @aorudpate pageset viewcount = viewcountwhere id = @ato aquire a lock in the beginning. thus you will have only locking w/o deadlocksIf this does not work out - show us the deadlock graphThanks, VadymMCITP DBA 2005/2008Chief DBA at http://www.db-staff.com
Thanks Vadym,What exactly is this doing?quote: select @a = id from page with (updlock)where id = @aor
|
 |
|
|
sduffy77
Starting Member
18 Posts |
Posted - 2009-03-19 : 15:42:13
|
| Any other ideas? |
 |
|
|
|
|
|