Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:38:55+00:00 2026-06-03T05:38:55+00:00

I have a notification table with the columns id, type, user_id and unseen. To

  • 0

I have a notification table with the columns id, type, user_id and unseen.

To get new notifications count i use:

SELECT count(1) 
FROM notifications 
WHERE user_id=123 AND unseen=1

To mark only new notifications as seen i use:

UPDATE notifications 
SET unseen=0 
WHERE user_id=123 AND unseen=1

But this update query sometimes gives an error. I want to know, what is the right way to do this?

Edit:

ERROR DESC
Transaction (Process ID 68) was deadlocked on lock; communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:38:56+00:00Added an answer on June 3, 2026 at 5:38 am

    It can be issue of deadlock, while you are trying to update the records, some is also reading those records.

    Your update statement is a complete statement, i think it is not running in a transaction. It seems, you want more priority to complete the updated statement instead of read statment (using select).

    For above mentioned scenario, you can allow phantom read (every time user use executes the select query gets different output) by using NoLock while reading. In your scenario, it will be not a dirty read because you will be reading only commited records.

    SELECT count(1) FROM notifications (NOLOCK) WHERE user_id=123 AND unseen=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called notification , with two columns: provider email The values
I currently have a notifications table in rails which contains the columns: notification_type, notification_id
I have a simple MySQL table for storing notification in a web with social
I have code like: @notifications = Notification.find_all_by_user_id(@user.id, :order=>'deliver_by DESC', :conditions=>deliver_by >= '#{Date.today.to_s(:db)}') logger.info @upcoming_reminders[0].inspect
I have a notifications table which contains different types of notifications for different events.
I have a Table, called Table1, with 3 columns: 1) id - An integer
I have 3 column table, I will need one of the columns to give
I'm attempting to use a prepared statement to select a value from an SQL
I have a Persons table and a Notifications table. There are lots of people
I have this method: - (void)reloadMessages:(NSNotification *)notification { NSLog(@RECIEVED NEW MESSAGES TO MessagesRootViewController); //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.