[{"id":"sqliteintermediate-001","courseId":"sqlite-intermediate","domain":"schema-and-types","topic":"WITHOUT ROWID tables","prompt":"A product table has one row per item, keyed by `sku INTEGER PRIMARY KEY`. Rows are small and are read mostly by sku. Which table layout fits the SQLite docs best?","hint":"Compare the cost of the two layouts for a single integer key.","explain":"Two layouts can hold the same rows. One keeps a hidden row number and organizes by it; the other organizes by the declared key. Which wins depends on the key's shape and on how large each row is.","source":"https://www.sqlite.org/withoutrowid.html","interaction":{"type":"single"},"options":[{"id":"a","text":"WITHOUT ROWID, since it always uses about half the disk space","whyNot":"The docs say about half the space in some cases, not always, so this saving is not guaranteed."},{"id":"b","text":"An ordinary rowid table, since a single INTEGER key already runs faster there","why":"The docs say ordinary rowid tables run faster when the only key is a single integer, so that is the layout to keep."},{"id":"c","text":"WITHOUT ROWID, since that layout is meant for integer keys","whyNot":"It is meant for non-integer or composite keys; a single integer key is a case the docs steer away from."},{"id":"d","text":"WITHOUT ROWID, since it runs faster for any row size","whyNot":"Rowid tables tend to run faster for large rows, and WITHOUT ROWID suits rows that are not too large."}],"answer":"b","explanation":"A WITHOUT ROWID table keeps one B-Tree keyed by the primary key. The docs advise it for non-integer or composite keys, while a single INTEGER key is better left as an ordinary rowid table.","concept":"A WITHOUT ROWID table keeps one B-Tree keyed by the primary key. The docs advise it for non-integer or composite keys, while a single INTEGER key is better left as an ordinary rowid table.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["WITHOUT ROWID helps with text or composite keys, not with a single INTEGER primary key."]},{"id":"sqliteintermediate-002","courseId":"sqlite-intermediate","domain":"schema-and-types","topic":"STRICT tables","prompt":"In a STRICT table, a column declared as ANY stores the text '000123' as the integer 123.","hint":"Compare how the ANY type behaves in the two table styles.","explain":"Some tables enforce each column's type on insert; others convert loosely. The ANY name lets one column hold any kind of value, and how a number-looking string is treated depends on the table's style.","source":"https://www.sqlite.org/stricttables.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"In a STRICT table, ANY keeps the value exactly as received, so the text stays text."},{"id":"b","text":"False","why":"Converting number-looking text to a number happens only in an ordinary non-strict table, where ANY preserves nothing extra."}],"answer":"b","explanation":"In a STRICT table, a column of type ANY always preserves the data exactly as it is received. Only an ordinary non-strict table lets ANY convert number-like strings to numbers.","concept":"In a STRICT table, a column of type ANY always preserves the data exactly as it is received. Only an ordinary non-strict table lets ANY convert number-like strings to numbers.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"CREATE TABLE t1(a ANY) STRICT;\nINSERT INTO t1 VALUES('000123');\nSELECT typeof(a) FROM t1;","takeaways":["ANY in a STRICT table keeps values as inserted; in an ordinary table it may convert numeric-looking text."]},{"id":"sqliteintermediate-003","courseId":"sqlite-intermediate","domain":"schema-and-types","topic":"Generated columns","prompt":"You are designing a table with a computed total column. Which TWO statements about generated columns are correct?","hint":"Think about what a computed value is allowed to carry, and how it can be written.","explain":"A generated column's value comes from an expression over its row, not from whoever writes the row. Its expression is limited to plain, self-contained calculations.","source":"https://www.sqlite.org/gencol.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The expression may use a subquery to look up related rows","whyNot":"Subqueries, aggregate functions and window functions are not allowed in a generated column's expression."},{"id":"b","text":"A generated column cannot have a DEFAULT clause","why":"The docs say a generated column may not have a default value, because its value always comes from the expression after AS."},{"id":"c","text":"Leaving out VIRTUAL or STORED makes the column STORED","whyNot":"When the trailing keyword is omitted, VIRTUAL is the default; STORED has to be written out."},{"id":"d","text":"A direct INSERT or UPDATE cannot set a generated column's value","why":"Generated columns can be read but not written directly; you change them by changing the columns their expression uses."},{"id":"e","text":"A generated column may be part of the PRIMARY KEY","whyNot":"The docs forbid using a generated column as part of the PRIMARY KEY."},{"id":"f","text":"PRAGMA table_info lists every generated column","whyNot":"Generated columns are left out of table_info and appear only in the newer table_xinfo output."}],"answer":"bd","explanation":"Generated columns can be read but not written directly, and they cannot have a DEFAULT clause; their value is always the result of the expression after AS.","concept":"Generated columns can be read but not written directly, and they cannot have a DEFAULT clause; their value is always the result of the expression after AS.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["A generated column is derived: you change it only by changing the columns its expression reads."]},{"id":"sqliteintermediate-004","courseId":"sqlite-intermediate","domain":"schema-and-types","topic":"AUTOINCREMENT keyword","prompt":"A table is declared with `id INTEGER PRIMARY KEY AUTOINCREMENT`. What does the AUTOINCREMENT keyword change compared with a plain INTEGER PRIMARY KEY?","hint":"Think about what the engine remembers after a row is removed.","explain":"Automatic keys are normally one above the current largest, which depends on what is in the table right now. A stricter numbering mode exists, but it costs extra bookkeeping on every insert.","source":"https://www.sqlite.org/autoinc.html","interaction":{"type":"single"},"options":[{"id":"a","text":"It makes ids consecutive, with no gaps left by deleted rows","whyNot":"Deleted rows still leave gaps; the keyword prevents reuse of old ids, it does not fill the gaps."},{"id":"b","text":"It makes inserts faster by skipping the search for a free id","whyNot":"The keyword adds CPU, memory and disk overhead; it does not speed up inserts."},{"id":"c","text":"It stops a new row from taking an id that a deleted row once held in this table","why":"AUTOINCREMENT tracks the largest id the table has ever held, so a new id is always above it."},{"id":"d","text":"It makes ids unique across every table in the database","whyNot":"The counter is kept per table in sqlite_sequence; other tables are not affected."}],"answer":"c","explanation":"AUTOINCREMENT makes each new ROWID at least one larger than any ROWID the table has ever held, which prevents reuse at the cost of extra overhead.","concept":"AUTOINCREMENT makes each new ROWID at least one larger than any ROWID the table has ever held, which prevents reuse at the cost of extra overhead.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"CREATE TABLE orders(\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  note TEXT\n);","takeaways":["AUTOINCREMENT prevents ROWID reuse but adds overhead, so use it only when reuse matters."]},{"id":"sqliteintermediate-005","courseId":"sqlite-intermediate","domain":"schema-and-types","topic":"Default collating sequence","prompt":"A column holds values of mixed kinds. Put these kinds in the order an ORDER BY clause places them, from first row to last.","hint":"Each kind forms its own block, and the empty value is treated specially.","explain":"A column can hold values of several kinds, and ordering keeps those kinds apart. Nothing is converted before the sort; each kind is compared by its own rules, and the kinds form blocks.","source":"https://www.sqlite.org/datatype3.html","interaction":{"type":"sort","items":[{"text":"NULL","why":"Missing values come first when ORDER BY sorts, ahead of every other kind."},{"text":"INTEGER and REAL","why":"Numbers come next and are compared by numeric value across both types."},{"text":"TEXT","why":"Strings follow, compared using the column's collating sequence."},{"text":"BLOB","why":"Binary blobs come last, compared byte by byte with memcmp()."}]},"options":[],"answer":"o:abcd","explanation":"ORDER BY sorts values by storage class in a fixed sequence: NULL first, then numbers, then text, then blobs, with no conversion before the sort.","concept":"ORDER BY sorts values by storage class in a fixed sequence: NULL first, then numbers, then text, then blobs, with no conversion before the sort.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["Mixed-type columns sort by kind first: missing values lead and blobs come last."]}]