[{"id":"sqlitebeginner-001","courseId":"sqlite-beginner","domain":"schema-and-types","topic":"Type affinity of columns","prompt":"You create a table and insert a number into a column declared TEXT. What does SQLite store in that column?","hint":"Think about what a column's preferred storage kind tells the engine to do with a number.","explain":"Every column has an affinity: a preferred storage kind set by its declared type name. The preference is only a recommendation, so a value of another kind can still be stored, though it may first be converted.","source":"https://www.sqlite.org/datatype3.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The text '42'","why":"A column with TEXT affinity converts numeric data to text form before storing it."},{"id":"b","text":"The integer 42","whyNot":"A NUMERIC or INTEGER column would keep 42 as a number, but a TEXT column converts it to text first."},{"id":"c","text":"An error, because 42 is not a string","whyNot":"SQLite does not reject a value just because its type differs from the declared type."},{"id":"d","text":"A BLOB holding the digit bytes","whyNot":"No BLOB is created; TEXT affinity converts numbers to text, not to binary data."}],"answer":"a","explanation":"A column's affinity is the storage class it prefers; a TEXT-affinity column converts numeric input to text form before storing it.","concept":"A column's affinity is the storage class it prefers; a TEXT-affinity column converts numeric input to text form before storing it.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"CREATE TABLE notes(body TEXT);\nINSERT INTO notes(body) VALUES(42);","takeaways":["A column's declared type sets its affinity, which converts values but does not reject them."]},{"id":"sqlitebeginner-002","courseId":"sqlite-beginner","domain":"schema-and-types","topic":"Storage classes of values","prompt":"Which TWO of these are storage classes that SQLite uses to hold a value?","hint":"Count the kinds of value the engine itself keeps, not the names people use when declaring columns.","explain":"The engine sorts every value into one of a few fixed internal kinds, and those are what the table really keeps. Names used when declaring a column belong to a different layer.","source":"https://www.sqlite.org/datatype3.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"NULL","why":"NULL is one of SQLite's storage classes, used to hold a missing value."},{"id":"b","text":"INTEGER","why":"INTEGER is a storage class for signed whole numbers, kept in as few bytes as the value needs."},{"id":"c","text":"DATETIME","whyNot":"SQLite has no storage class for dates or times; they are kept as TEXT, REAL or INTEGER."},{"id":"d","text":"BOOLEAN","whyNot":"SQLite has no Boolean storage class; true and false are stored as the integers 1 and 0."},{"id":"e","text":"VARCHAR(255)","whyNot":"A type name you can write when declaring a column, not one of the kinds a stored value can have."},{"id":"f","text":"NUMERIC","whyNot":"NUMERIC is a column affinity, not a storage class; a NUMERIC column may hold values of all five."}],"answer":"ab","explanation":"SQLite stores each value in one of five storage classes (NULL, INTEGER, REAL, TEXT, BLOB); names like BOOLEAN and DATETIME are not among them.","concept":"SQLite stores each value in one of five storage classes (NULL, INTEGER, REAL, TEXT, BLOB); names like BOOLEAN and DATETIME are not among them.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["Only NULL, INTEGER, REAL, TEXT and BLOB are storage classes; declared type names are not."]},{"id":"sqlitebeginner-003","courseId":"sqlite-beginner","domain":"schema-and-types","topic":"Rowid of ordinary tables","prompt":"In an ordinary rowid table with no INTEGER PRIMARY KEY, SQLite can change a row's rowid when the VACUUM command runs.","hint":"Consider whether a row's internal key is promised to stay the same over time.","explain":"Each ordinary table row has a hidden 64-bit integer key that the engine uses to locate it. Whether that key stays put depends on how the table declares its key column.","source":"https://www.sqlite.org/rowidtable.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"VACUUM can renumber rowids of tables that lack an INTEGER PRIMARY KEY, because those rowids are not persistent."},{"id":"b","text":"False","whyNot":"A rowid that is not aliased by an INTEGER PRIMARY KEY is not persistent, so VACUUM is allowed to change it."}],"answer":"a","explanation":"An ordinary rowid table's rowid is not persistent unless the table declares an INTEGER PRIMARY KEY, and VACUUM may renumber such rowids.","concept":"An ordinary rowid table's rowid is not persistent unless the table declares an INTEGER PRIMARY KEY, and VACUUM may renumber such rowids.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["Use an INTEGER PRIMARY KEY, not the rowid, for an identifier that must stay the same."]},{"id":"sqlitebeginner-004","courseId":"sqlite-beginner","domain":"schema-and-types","topic":"INTEGER PRIMARY KEY as rowid alias","prompt":"You want the column id to be an alias for the table's rowid. Which column definition does that?","hint":"Pay attention to the exact declared type name and to whether the column is the primary key.","explain":"Ordinary tables give every row a hidden identifier that the engine uses internally. A column can be tied to that identifier, but only when its declaration meets exact conditions on spelling and role.","source":"https://www.sqlite.org/lang_createtable.html","interaction":{"type":"single"},"options":[{"id":"a","text":"id INTEGER PRIMARY KEY","why":"A single-column primary key declared with exactly the type name INTEGER becomes an alias for the rowid."},{"id":"b","text":"id INT PRIMARY KEY","whyNot":"INT is a different type name, so the column is an ordinary integer column with a unique index, not a rowid alias."},{"id":"c","text":"id INTEGER UNIQUE","whyNot":"UNIQUE is not a primary key, so the column does not become an alias for the rowid."},{"id":"d","text":"id BIGINT PRIMARY KEY","whyNot":"BIGINT is also a different type name, so it does not become a rowid alias."}],"answer":"a","explanation":"Only a single-column primary key declared with the exact type name INTEGER becomes an alias for the rowid; INT, BIGINT and UNIQUE do not.","concept":"Only a single-column primary key declared with the exact type name INTEGER becomes an alias for the rowid; INT, BIGINT and UNIQUE do not.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["Other integer type names such as INT or BIGINT do not create a rowid alias."]},{"id":"sqlitebeginner-005","courseId":"sqlite-beginner","domain":"schema-and-types","topic":"NOT NULL constraint","prompt":"In SQLite, a text column is the table's primary key, and you insert NULL into it. What happens?","hint":"Compare what the SQL standard expects with SQLite's actual behavior for this column.","explain":"The SQL standard expects a column that uniquely names each entry to refuse unknown values. An engine may depart from that, and the exceptions depend on the table type and on how the column is declared.","source":"https://www.sqlite.org/lang_createtable.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The row is inserted; SQLite allows NULL in this primary key.","why":"In an ordinary table, SQLite allows NULL in a non-integer primary key unless the column is declared NOT NULL."},{"id":"b","text":"The insert fails, because a primary key always implies NOT NULL.","whyNot":"The SQL standard says so, but SQLite does not follow that for most primary key columns."},{"id":"c","text":"The insert fails only if another row already holds NULL.","whyNot":"NULL values are distinct for uniqueness, so an existing NULL never blocks a new one."},{"id":"d","text":"The NULL is silently replaced by an empty string.","whyNot":"No conversion happens; the NULL is stored as it is."}],"answer":"a","explanation":"SQLite allows NULL in a PRIMARY KEY column unless it is an INTEGER PRIMARY KEY, the table is WITHOUT ROWID or STRICT, or the column is NOT NULL.","concept":"SQLite allows NULL in a PRIMARY KEY column unless it is an INTEGER PRIMARY KEY, the table is WITHOUT ROWID or STRICT, or the column is NOT NULL.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"CREATE TABLE codes(\n  code TEXT PRIMARY KEY\n);\nINSERT INTO codes(code) VALUES(NULL);","takeaways":["Add NOT NULL to key columns that must always have a value; SQLite does not infer it."]}]