This is a discussion on Select Insert Deadlock within the SQL Server forums, part of the Microsoft SQL Server category; --> Lets say we select from TableA that joins to TableB TableB also gets data inserted into into it via ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Lets say we select from TableA that joins to TableB TableB also gets data inserted into into it via another query. So I guess SQL server places a shared lock on Table A and Table B. and the insert will try and put an exclusive lock on the table. We then get a deadlock. What I am trying to get my head around is why? I would have thought that the Insert query would wait until the lock was released on table B. Ok the select query does take a long time, but I would have thought the insert would time out. I know there is something I am missing in my logic. I am just trying to figure out how the tables become deadlocked in this situation. TIA |
| ||||
| bozzzza (bozzzza@googlemail.com) writes: > Lets say we select from TableA that joins to TableB > > TableB also gets data inserted into into it via another query. > > So I guess SQL server places a shared lock on Table A and Table B. > and the insert will try and put an exclusive lock on the table. > > We then get a deadlock. What I am trying to get my head around is why? > I would have thought that the Insert query would wait until the lock > was released on table B. Ok the select query does take a long time, > but I would have thought the insert would time out. Without seeing the queries and the query plans, the field is open for wild speculations. But to start with, locks are far from always on table level. Most commonly locks are on row level, or key level in case of an index. I would guess the problem has to do with index and data pages being access in different order. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx |
| Thread Tools | |
| Display Modes | |
|
|
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DEADLOCK INSERT | Ricardo Durao | pgsql Admins | 0 | 04-10-2008 05:54 AM |
| insert deadlock | Brian Cox | Pgsql General | 2 | 04-09-2008 08:19 AM |
| Deadlock within select? | jw_guildford@yahoo.co.uk | SQL Server | 2 | 02-29-2008 07:20 PM |
| Parellel insert causes deadlock | Prakash | DB2 | 3 | 02-26-2008 03:40 PM |
| Oracle 8i Deadlock without deadlock graph on insert statement | vdemers@gmail.com | Oracle Database | 0 | 02-26-2008 08:10 AM |