How to use PRAGMA Statements In SQL
Using the following formula, we can calculate the database size in SQLite Database.
We will use two PRAGMA statements:
- PRAGMA page_count: This statement retrieves the total number of pages in the SQLite database.
- PRAGMA page_size: This statement retrieves the size of each page in bytes.
After executing the PRAGMA statements, we will use the values obtained to calculate the total size of the database. This is done by multiplying the total number of pages (page_count) by the size of each page (page_size).
Finally, the total size of the SQLite database in bytes, is calculated using the retrieved page count and page size.
Query:
PRAGMA page_count;
PRAGMA page_size;
Output:
We then calculate the database size by multiplying the page count by the page size:
Database Size = 4 * 4096 = 16384 bytes
Explanation:
- The PRAGMA page_count: Statement returns the total number of pages in the database, which in this case is 4.
- The PRAGMA page_size: Statement returns the size of each page in bytes, which is 4096.
How to Get SQLite Database Size
SQLite is a lightweight and serverless SQL database. It is widely used in mobile devices and embedded systems due to its simplicity and efficiency. To understand how to manage SQLite databases efficiently, it is very important to know the Database size in SQLite. In this article, we will learn about different approaches to get the SQLite Database Size.
To retrieve the size of a SQLite database, you can use the PRAGMA statement along with the page_count and page_size properties.
Syntax:
Database Size = page_count * page_size
- page_count is the total number of pages in the database.
- page_size is the size of each page in bytes.