The three schema architecture splits the description of one database into three levels, and each level answers a different question.
The external schema describes what each user or program sees. It is the view layer, and it is defined per group of users. The internal schema describes the physical storage: files, pages, indexes and record layout. The conceptual schema sits between them and describes the whole database for all users at once, with entities, relationships and constraints.
The rule that makes the split worth having is simple. A change at one level should not force a change at the level above it.
In the snippet, the view customer_totals is the external schema. The application asks for a full name and a lifetime value, and it never mentions orders.
The customers and orders tables are the conceptual schema, because they model the real world as entities and relationships.
The last statement reads sqlite_master, which is the internal level. It lists the stored tables and views, which is as close as a small engine comes to showing you pages on disk.
The mappings are what hold the levels together. The external to conceptual mapping lives in the view definition. The conceptual to internal mapping lives inside the engine, as statistics and layout rules.
One caution. The three levels are a logical design tool, not a physical one. A single table can play more than one role in practice, and most small engines collapse the levels into one file.
A SELECT statement passes through the three levels in a fixed order, and each level does one job on the way.
First the statement is parsed and checked against the external schema. This is where a column name is resolved to a table in the view the user is allowed to see.
Second the logical plan is built. The conceptual schema supplies the real tables, the join conditions and the constraint rules that make the plan valid.
Third the optimizer picks a physical plan. The internal schema decides the outcome here, because only it knows the row counts, the index layout and the page sizes.
Fourth the storage engine executes the plan and hands the rows back up the stack.
Fifth the result is mapped down through the external schema, so the user sees the column names and shapes they asked for.
Two details make this clearer in practice. A view is expanded before the optimizer sees it, so the plan is built on the base tables rather than on the view. And a permission check happens at the external level, so a user can be blocked by a view without the base table ever being touched.
Why is this worth knowing? Because it tells you where to look when a query fails. A missing column error is an external schema problem. A constraint violation comes from the conceptual level. A slow query is usually an internal schema problem, and the fix is usually an index or fresh statistics rather than a rewrite of the SQL.
Logical data independence means the conceptual schema can change while the programs built on it keep working unchanged.
The classic case is a city stored as free text on the customer row being replaced by an identifier that points at a lookup table. The application still wants to show a city name, so the change is hidden inside a view and a mapping.
Before the change the view selects the column straight from the customer table. After the change it selects from the customer table and joins to the city table. The application query is identical in both cases, and it returns identical rows.
Here is what the snippet does, step by step.
It creates the customers table with a city column, plus a view called customer_report. The first select shows the shape the application expects: a full name and a city name.
Then it adds the cities table, drops the view, renames the column to city_id and backfills the identifiers.
Then it rebuilds the view with a join, which is the new mapping between the external and conceptual levels.
The final select returns Asha Rao with Chennai and Ben Das with Pune, exactly what the first select returned.
Two limits are worth naming. A program that wrote the old column name directly would break, unless it also went through the view. And the mapping has to be maintained by hand, because no engine can guess that the identifier 1 and the text Chennai mean the same thing.