# Database Locks

Source: <https://www.linkedin.com/posts/alexxubyte_systemdesign-coding-interviewtips-activity-7211031615462895616-678T?utm_source=share&utm_medium=member_desktop>

Here are the common types of locks used in databases:

1. Shared Lock (S Lock) It allows multiple transactions to read a resource simultaneously but not modify it. Other transactions can also acquire a shared lock on the same resource.
2. Exclusive Lock (X Lock) allows a transaction to read and modify a resource. No other transaction can acquire any lock on the same resource while an exclusive lock is held.
3. Update Lock (U Lock) It prevents a deadlock scenario when a transaction intends to update a resource.
4. Schema Lock It is used to protect the structure of database objects.
5. Bulk Update Lock (BU Lock): This is used during bulk insert operations to improve performance by reducing the number of locks required.
6. Key-Range Lock It is used in indexed data to prevent phantom reads (inserting new rows into a range that a transaction has already read).
7. Row-Level Lock: It locks a specific row in a table, allowing other rows to be accessed concurrently.
8. Page-Level Lock: It locks a specific page (a fixed-size block of data) in the database.
9. Table-Level Lock It locks an entire table. This is simple to implement but can reduce concurrency significantly.

<figure><img src="/files/jeujoADJrqw6QomBeM6d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gchandra.gitbook.io/general/database-locks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
