[{"id":"mysqlbeginner-001","courseId":"mysql-beginner","domain":"schema-and-data-types","topic":"Implicit NOT NULL on primary keys","prompt":"A teammate creates this table and leaves NOT NULL off the id column. Can a row be inserted with id set to NULL?","hint":"Think about what a primary key requires of its columns, and what MySQL does when you do not say so.","explain":"A primary key is a unique index that identifies each row. Its columns follow rules that the server enforces, whether or not the CREATE TABLE statement repeats them.","source":"https://dev.mysql.com/doc/refman/8.4/en/create-table.html","interaction":{"type":"single"},"options":[{"id":"a","text":"No. MySQL makes a primary key column NOT NULL on its own, so NULL is refused.","why":"A PRIMARY KEY column must be NOT NULL, and when the clause is missing MySQL declares it so implicitly."},{"id":"b","text":"Yes. Without an explicit NOT NULL, the id column accepts NULL and only the uniqueness rule applies.","whyNot":"Uniqueness is one rule of a primary key; NOT NULL is the other, and MySQL adds it when you omit it."},{"id":"c","text":"Yes, but MySQL logs a warning and stores the row.","whyNot":"MySQL adds NOT NULL silently, with no warning, and a NULL id is not stored."},{"id":"d","text":"Yes, but only one row may hold NULL, because primary keys are unique.","whyNot":"Uniqueness does not allow NULL here; a NULL id is refused, not stored once."}],"answer":"a","explanation":"A PRIMARY KEY is a unique index whose columns must be NOT NULL; when NOT NULL is not written, MySQL declares it implicitly and silently.","concept":"A PRIMARY KEY is a unique index whose columns must be NOT NULL; when NOT NULL is not written, MySQL declares it implicitly and silently.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"CREATE TABLE users (\n  id INT PRIMARY KEY,\n  name VARCHAR(50)\n);","takeaways":["Primary key columns can never hold NULL, even if you leave NOT NULL out."]},{"id":"mysqlbeginner-002","courseId":"mysql-beginner","domain":"schema-and-data-types","topic":"AUTO_INCREMENT after explicit values","prompt":"After you insert id 100 by hand into an AUTO_INCREMENT column holding ids 1 to 8, the next row inserted without an id gets id 101.","hint":"Consider where the counter goes after you set a value yourself.","explain":"An AUTO_INCREMENT column hands out the next number in a sequence when you leave it out. Setting a value yourself also changes where that sequence continues from.","source":"https://dev.mysql.com/doc/refman/8.4/en/example-auto-increment.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The sequence resumes from the largest value in the column, so after 100 the next generated id is 101."},{"id":"b","text":"False","whyNot":"Explicit values do change the sequence; MySQL does not ignore 100 and continue from 9."}],"answer":"a","explanation":"Inserting an explicit value into an AUTO_INCREMENT column resets the sequence so the next generated value follows the largest column value.","concept":"Inserting an explicit value into an AUTO_INCREMENT column resets the sequence so the next generated value follows the largest column value.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["An explicit id above the current maximum moves the auto-increment counter past it."]},{"id":"mysqlbeginner-003","courseId":"mysql-beginner","domain":"schema-and-data-types","topic":"CHAR and VARCHAR storage","prompt":"You store the value 'ab' in a CHAR(4) column and in a VARCHAR(4) column, using a single-byte character set. Which TWO statements are true?","hint":"Compare how each type handles the spaces that fill out its declared length.","explain":"CHAR and VARCHAR both take a declared length, but they store that length differently. Trailing spaces and the bytes a value uses are the details to watch.","source":"https://dev.mysql.com/doc/refman/8.4/en/char.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The CHAR(4) column stores 'ab' as 'ab  ', using 4 bytes.","why":"CHAR values are right-padded with spaces to the declared length, so the stored value takes all 4 bytes."},{"id":"b","text":"The VARCHAR(4) column stores 'ab' in 3 bytes: a length prefix plus the two characters.","why":"VARCHAR stores a 1-byte length prefix followed by the data, so 'ab' needs 3 bytes."},{"id":"c","text":"The VARCHAR(4) column pads 'ab' with two spaces, just as CHAR does.","whyNot":"VARCHAR values are not padded when stored; only the characters and the length prefix are kept."},{"id":"d","text":"Selecting the VARCHAR(4) column returns 'ab  ' with two spaces added back.","whyNot":"VARCHAR stores 'ab' as given and returns it unchanged, so no spaces are added on retrieval."},{"id":"e","text":"Both columns use 4 bytes, because every value is stored at its full declared length.","whyNot":"Only CHAR is stored at full length; VARCHAR stores just the value plus its length prefix."},{"id":"f","text":"The CHAR(4) column keeps 'ab' as 2 bytes, since it stores only the characters given.","whyNot":"CHAR always takes its declared length, so 'ab' is padded out to 4 bytes."}],"answer":"ab","explanation":"CHAR(n) is stored padded to n characters, and by default trailing spaces are dropped on retrieval unless PAD_CHAR_TO_FULL_LENGTH is enabled; VARCHAR stores only the value plus a 1- or 2-byte length prefix.","concept":"CHAR(n) is stored padded to n characters, and by default trailing spaces are dropped on retrieval unless PAD_CHAR_TO_FULL_LENGTH is enabled; VARCHAR stores only the value plus a 1- or 2-byte length prefix.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["CHAR pads values to its length; VARCHAR stores what you give it plus a length prefix."]},{"id":"mysqlbeginner-004","courseId":"mysql-beginner","domain":"schema-and-data-types","topic":"DECIMAL for exact money","prompt":"A price column is declared DECIMAL(5,2) to keep exact cents. What is the largest value it can store?","hint":"Work out what the two numbers in the declaration mean: total digits and digits after the point.","explain":"DECIMAL stores exact numbers, which suits money. Its declaration sets a precision, the total number of significant digits, and a scale, how many of those digits come after the decimal point.","source":"https://dev.mysql.com/doc/refman/8.4/en/fixed-point-types.html","interaction":{"type":"single"},"options":[{"id":"a","text":"999.99","why":"DECIMAL(5,2) holds five digits in total, two of them after the point, so the range runs from -999.99 to 999.99."},{"id":"b","text":"99999.99","whyNot":"That has seven digits in total; the precision of 5 includes the two digits after the point."},{"id":"c","text":"99.999","whyNot":"That puts three digits after the point, which exceeds the scale of 2."},{"id":"d","text":"9999.99","whyNot":"That has six digits in total, one more than the precision of 5 allows."}],"answer":"a","explanation":"DECIMAL(M,D) stores exact values with M total digits and D after the point; DECIMAL(5,2) ranges from -999.99 to 999.99.","concept":"DECIMAL(M,D) stores exact values with M total digits and D after the point; DECIMAL(5,2) ranges from -999.99 to 999.99.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"CREATE TABLE items (\n  price DECIMAL(5,2)\n);","takeaways":["DECIMAL(M,D) fixes both total digits and digits after the point; use it for money."]},{"id":"mysqlbeginner-005","courseId":"mysql-beginner","domain":"schema-and-data-types","topic":"DATETIME and TIMESTAMP ranges","prompt":"In MySQL 8.4, a TIMESTAMP column accepts the same date range as a DATETIME column, so '9999-12-31' can be stored in either.","hint":"Think about the latest year each of these types can hold.","explain":"MySQL has several date and time types, and each supports its own span of dates. The span matters when you choose a type, and TIMESTAMP values are also converted to UTC for storage.","source":"https://dev.mysql.com/doc/refman/8.4/en/datetime.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"TIMESTAMP stops at 2038-01-19 03:14:07 UTC, far short of the year 9999 that DATETIME reaches."},{"id":"b","text":"False","why":"DATETIME runs to '9999-12-31 23:59:59', but TIMESTAMP ends in 2038, so '9999-12-31' is outside its range."}],"answer":"b","explanation":"DATETIME's supported range runs to 9999-12-31, while TIMESTAMP's range ends at 2038-01-19 03:14:07 UTC.","concept":"DATETIME's supported range runs to 9999-12-31, while TIMESTAMP's range ends at 2038-01-19 03:14:07 UTC.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["TIMESTAMP caps out in 2038; choose DATETIME for dates beyond that."]}]