UPDATE and INSERT queries lock relevant row/table while query executes. But does SELECT also locks the tables? What other types cause DB locks? Does this vary by DB?
Edit: Added sql-server tag. When is nolock useful?
UPDATE and INSERT queries lock relevant row/table while query executes. But does SELECT also locks the tables? What other types cause DB locks? Does this vary by DB?
Edit: Added sql-server tag. When is nolock useful?
Basic RTFM?
This IS a complex topic, so please read the extensive documentation.
SELECT does lead to locks IF the connection and transaction settings demand that. This is to allow what is called a "repeatable read" in a transaction, which means a read row can not be changed until the reading transaction commits or rolls back.
EVERYTHING - literally - CAN cause locks. The problem is that most of this is defined in the transaction (or by default connection) settings. This really is a section you must read in the documentation because it is not a "one page" - it goes over a lot of details. It can also be changed in a SELECT statement (allowing to IGNORE locks, when I say read uncommitted for example).