Textbook: Database Management Systems by Ramakrishnan and Gehrke.
Or: Architecture of a Database System by Hellerstein, Stonebraker, and Hamilton.
Production Code: PostgreSQL
(I like the PG code better than SQLite , it's far more complete and, I think, better organized. SQLite is awesome for what it does, but there is a lot it doesn't take on).
Extra Credit: Readings in Database Systems, 4th edition edited by Hellerstein.