[{"id":"mysqlintermediate-001","courseId":"mysql-intermediate","domain":"schema-and-data-types","topic":"VIRTUAL versus STORED generated columns","prompt":"The table below has a column defined with AS (price * qty) and no storage keyword. Which storage type does MySQL 8.4 give that column?","hint":"The storage keyword is optional. Check what MySQL uses when it is left out.","explain":"A generated column gets its value from an expression. A storage keyword decides whether the computed value is kept in the table or worked out on each read, and the keyword is optional.","source":"https://dev.mysql.com/doc/refman/8.4/en/create-table-generated-columns.html","interaction":{"type":"single"},"options":[{"id":"a","text":"STORED, because generated columns are kept in the table by default","whyNot":"Storing is opt-in: values are kept in the table only when STORED is written."},{"id":"b","text":"VIRTUAL, the default when neither keyword is written","why":"VIRTUAL is the default when neither VIRTUAL nor STORED is specified."},{"id":"c","text":"STORED, because the expression is evaluated only once, at CREATE TABLE","whyNot":"STORED values are evaluated when rows are inserted or updated, not when the table is created."},{"id":"d","text":"No storage keyword is allowed, so the definition is rejected","whyNot":"The keyword is optional in the syntax, so leaving it out is valid."}],"answer":"b","explanation":"VIRTUAL is the default for generated columns. VIRTUAL values are evaluated when rows are read and take no storage; STORED values are computed on insert and update.","concept":"VIRTUAL is the default for generated columns. VIRTUAL values are evaluated when rows are read and take no storage; STORED values are computed on insert and update.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"CREATE TABLE line_items (\n  price DECIMAL(10,2),\n  qty   INT,\n  total DECIMAL(10,2) AS (price * qty)\n);","takeaways":["Omitting both VIRTUAL and STORED makes a generated column VIRTUAL.","A STORED generated column takes storage space but can be indexed."]},{"id":"mysqlintermediate-002","courseId":"mysql-intermediate","domain":"schema-and-data-types","topic":"ON DELETE CASCADE","prompt":"In InnoDB, orders.customer_id references customers.id with ON DELETE CASCADE, as in the code. A customer row is deleted. Which TWO statements are true?","hint":"Think about what the referential action in the clause tells the child table to do.","explain":"A foreign key can name a referential action that runs when a parent row is deleted or updated. The actions differ in whether they reject the change, change the child rows, or null them out.","source":"https://dev.mysql.com/doc/refman/8.4/en/create-table-foreign-keys.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Triggers defined on orders do not fire for the cascaded deletes.","why":"Cascaded foreign key actions do not activate triggers."},{"id":"b","text":"The delete is rejected while any order still refers to the customer.","whyNot":"That is the RESTRICT behavior, which applies when the ON DELETE clause is omitted."},{"id":"c","text":"Matching rows in orders are deleted automatically.","why":"CASCADE deletes the matching child rows along with the parent row."},{"id":"d","text":"The customer_id in matching orders is set to NULL instead.","whyNot":"That is SET NULL; CASCADE deletes the child rows rather than nulling them."},{"id":"e","text":"Matching orders get the column's default value instead.","whyNot":"SET DEFAULT is recognized by the parser, but InnoDB rejects table definitions that use it."},{"id":"f","text":"CASCADE only works when the child column is declared NOT NULL.","whyNot":"The NOT NULL caution in the docs applies to SET NULL, not to CASCADE."}],"answer":"ac","explanation":"ON DELETE CASCADE deletes the matching child rows together with the parent row, and cascaded foreign key actions do not activate triggers.","concept":"ON DELETE CASCADE deletes the matching child rows together with the parent row, and cascaded foreign key actions do not activate triggers.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"CREATE TABLE orders (\n  id INT PRIMARY KEY,\n  customer_id INT,\n  FOREIGN KEY (customer_id)\n    REFERENCES customers (id)\n    ON DELETE CASCADE\n);","takeaways":["CASCADE removes matching child rows along with the parent row.","Cascaded foreign key actions do not fire triggers on the child table."]},{"id":"mysqlintermediate-003","courseId":"mysql-intermediate","domain":"schema-and-data-types","topic":"CHECK constraint evaluation","prompt":"Table orders already exists with CONSTRAINT chk_qty CHECK (qty > 0), as in the code. Later, CREATE TABLE refunds runs in the same database and declares CONSTRAINT chk_qty CHECK (amount > 0). What happens?","hint":"Think about the scope a constraint name must be unique in, not just the table.","explain":"Every CHECK constraint has a name, given explicitly or generated by MySQL. Uniqueness of a name is enforced within a scope, and that scope depends on the constraint kind and its database.","source":"https://dev.mysql.com/doc/refman/8.4/en/create-table-check-constraints.html","interaction":{"type":"single"},"options":[{"id":"a","text":"It succeeds, since CHECK names only need to be unique within each table.","whyNot":"CHECK constraint names must be unique per schema, not per table."},{"id":"b","text":"It succeeds, because the two checks use different columns.","whyNot":"The clash is about the name alone; the column a check uses does not matter."},{"id":"c","text":"It fails: the name is already used by another CHECK constraint in the schema.","why":"Two tables in the same schema cannot share a CHECK constraint name."},{"id":"d","text":"It succeeds, and MySQL silently renames the new constraint.","whyNot":"MySQL generates names only for CHECK constraints given none; it does not rename a named one."}],"answer":"c","explanation":"CHECK constraint names must be unique per schema, not per table, so two tables in one schema cannot share a CHECK constraint name.","concept":"CHECK constraint names must be unique per schema, not per table, so two tables in one schema cannot share a CHECK constraint name.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"CREATE TABLE orders (\n  qty INT,\n  CONSTRAINT chk_qty CHECK (qty > 0)\n);","takeaways":["CHECK constraint names are unique per schema.","Generated CHECK names should start with the table name to stay unique."]},{"id":"mysqlintermediate-004","courseId":"mysql-intermediate","domain":"schema-and-data-types","topic":"utf8mb4 versus utf8mb3","prompt":"A column uses the utf8mb3 character set, and the app needs to store a supplementary character. Which statement about utf8mb3 is correct?","hint":"Compare the range of characters each set supports, and how many bytes each uses.","explain":"MySQL has two UTF-8 character sets. They differ in the largest number of bytes one character can take and in which kinds of Unicode characters they can hold at all.","source":"https://dev.mysql.com/doc/refman/8.4/en/charset-unicode-utf8mb4.html","interaction":{"type":"single"},"options":[{"id":"a","text":"utf8mb3 stores a supplementary character in four bytes, like utf8mb4.","whyNot":"Four bytes is utf8mb4's limit; utf8mb3 uses at most three bytes per character."},{"id":"b","text":"utf8mb3 stores a supplementary character split across two characters.","whyNot":"No splitting happens: utf8mb3 cannot hold a supplementary character at all."},{"id":"c","text":"utf8mb3 cannot store a supplementary character at all.","why":"utf8mb3 supports only BMP characters, so supplementary characters are out of its reach."},{"id":"d","text":"utf8mb3 holds everything utf8mb4 does, since it is the larger set.","whyNot":"It is the reverse: utf8mb4 is a superset of utf8mb3."}],"answer":"c","explanation":"utf8mb3 supports only BMP characters in at most three bytes; utf8mb4 supports supplementary characters too, in up to four bytes.","concept":"utf8mb3 supports only BMP characters in at most three bytes; utf8mb4 supports supplementary characters too, in up to four bytes.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["utf8mb4 is a superset of utf8mb3.","Supplementary characters need utf8mb4; utf8mb3 cannot store them."]},{"id":"mysqlintermediate-005","courseId":"mysql-intermediate","domain":"schema-and-data-types","topic":"Collation comparison rules","prompt":"A column uses a case-insensitive collation. Statement: the comparison 'a' = 'A' is true.","hint":"Think about what a collation adds on top of a character set.","explain":"A character set lists symbols and their encodings. A collation adds comparison rules, and one common rule decides whether letter case counts when two strings are compared.","source":"https://dev.mysql.com/doc/refman/8.4/en/charset-general.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"A case-insensitive collation treats lowercase letters as equivalent to uppercase before comparing encodings."},{"id":"b","text":"False","whyNot":"That belief fits a binary collation, which compares encodings directly, but not a case-insensitive one."}],"answer":"a","explanation":"A case-insensitive collation treats lowercase letters as equivalent to uppercase before comparing encodings, so 'a' and 'A' compare equal.","concept":"A case-insensitive collation treats lowercase letters as equivalent to uppercase before comparing encodings, so 'a' and 'A' compare equal.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["The collation, not the character set, sets the comparison rules.","Under a case-insensitive collation, 'a' and 'A' compare equal."]}]