The Numbers Your Own Database Can Tell You
The most trustworthy figures you will ever see about a database are the ones it reports about your own data. You do not need special tools to read them. This page shows four kinds of numbers a beginner can get with a few short commands.
1. How many rows are there?
The simplest and most useful number. COUNT(*) counts rows:
SELECT COUNT(*) FROM books;
You can count only the rows that match a condition:
SELECT COUNT(*) FROM books WHERE year_published < 2000;
Why it matters: if a query returns far more or fewer rows than you expected, the count is the first clue that a condition or a join is wrong.
2. How many rows did my change affect?
When you run UPDATE or DELETE, the database reports how many rows were changed. In Python's sqlite3 module you can read it like this:
cur = conn.execute("UPDATE books SET in_stock = 0 WHERE copies = 0")
print(cur.rowcount) # number of rows updated
Why it matters: if you meant to update one row and the number says 500, stop and check before you commit.
3. How long did the query take?
In the sqlite3 command-line shell, turn on the timer:
sqlite> .timer on
sqlite> SELECT COUNT(*) FROM books;
After each query, the shell prints how long it took. PostgreSQL's psql has a similar switch, \timing.
Why it matters: timing helps you notice when a query gets slower as your data grows. Remember that a single run can be misleading; our beginner's method for timing a query explains how to measure fairly.
4. How is the database planning to run my query?
Every database can describe its plan. In SQLite:
EXPLAIN QUERY PLAN SELECT * FROM books WHERE author_id = 7;
You might see SCAN books, which means it reads every row, or SEARCH books USING INDEX ..., which means it can jump straight to the matching rows.
Why it matters: a scan is fine for small tables. If a table grows large and you query it often by one column, an index can help. That is a topic for later, but it is good to know the plan exists.
Summary table
| Question | Command or property | Where |
|---|---|---|
| How many rows? | SELECT COUNT(*) | Any SQL database |
| How many rows changed? | rowcount or the "rows affected" message | Driver or shell |
| How long did it take? | .timer on / \timing | sqlite3 shell / psql |
| How will it run? | EXPLAIN QUERY PLAN / EXPLAIN | SQLite / most others |
A good habit to start now
Before and after any change to data, run a quick count. It takes seconds and catches many mistakes, such as an UPDATE missing its WHERE clause. Professional developers do exactly the same thing, just on bigger tables.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.
General commentary only: this page does not report specific news events and does not cite a survey or data source. Treat any trends described as unverified.