0

I have a query in which I am updating a table and have used IN keyword in the query. The query is something like this:

UPDATE q 
SET b_id = 123     
WHERE id IN (SELECT id FROM q WHERE b_id IS NULL LIMIT 1)

There is another query in which I am inserting data in table. The query is:

INSERT INTO q (id, item) VALUES (@id, @item)

The queries are executing on different threads. While executing the second (INSERT) query I am getting database is locked error.

What is the reason?

id is not primary key.

3
  • Please edit your question. Add table's DDL and real queries texts (you can simplify them by removing the fields unnesessary for the question). And remove unproper DBMS tag.
    – Akina
    Commented Apr 25, 2019 at 6:53
  • The query is something like this It is EXTREMELY strange. 1) subquery selects random record; 2) main query updates random record with selected random id (maybe the record where b_id is not null, if id is not unique).
    – Akina
    Commented Apr 25, 2019 at 7:56
  • 2

0

Browse other questions tagged or ask your own question.