Challenge - 5 Problems
CREATE TABLE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this CREATE TABLE statement?
Consider the following SQL statement:
What will happen when this statement is executed in a standard SQL database?
CREATE TABLE Employees (ID INT PRIMARY KEY, Name VARCHAR(50), Age INT);
What will happen when this statement is executed in a standard SQL database?
SQL
CREATE TABLE Employees (ID INT PRIMARY KEY, Name VARCHAR(50), Age INT);
Attempts:
2 left
💡 Hint
Think about what PRIMARY KEY means and if the syntax for VARCHAR is correct.
✗ Incorrect
The statement correctly creates a table named Employees with three columns. ID is set as the primary key, which means it uniquely identifies each row. VARCHAR(50) is valid syntax for a string up to 50 characters.
📝 Syntax
intermediate2:00remaining
Which CREATE TABLE statement has a syntax error?
Identify which of the following CREATE TABLE statements will cause a syntax error in standard SQL.
Attempts:
2 left
💡 Hint
Check the datatype MONEY and its parameters.
✗ Incorrect
The MONEY datatype does not accept precision and scale parameters like DECIMAL does. Using MONEY(10,2) causes a syntax error.
🧠 Conceptual
advanced2:00remaining
What is the purpose of the PRIMARY KEY constraint in CREATE TABLE?
Why do we use PRIMARY KEY in a CREATE TABLE statement? Choose the best explanation.
Attempts:
2 left
💡 Hint
Think about what makes each row in a table unique.
✗ Incorrect
PRIMARY KEY enforces uniqueness and disallows NULLs, ensuring each row can be uniquely identified by that column or set of columns.
🔧 Debug
advanced2:00remaining
Why does this CREATE TABLE statement fail?
Examine this SQL statement:
Why will this statement cause an error?
CREATE TABLE Inventory (ItemID INT, Quantity INT DEFAULT 'ten');
Why will this statement cause an error?
SQL
CREATE TABLE Inventory (ItemID INT, Quantity INT DEFAULT 'ten');
Attempts:
2 left
💡 Hint
Check the data type of the DEFAULT value compared to the column type.
✗ Incorrect
The DEFAULT value must match the column's datatype. 'ten' is a string and cannot be used as a default for an INT column.
❓ optimization
expert3:00remaining
Which CREATE TABLE design is best for fast lookups on a large dataset?
You need to create a table to store millions of user records and want fast lookups by user email. Which CREATE TABLE statement is best optimized for this?
Attempts:
2 left
💡 Hint
Consider constraints that help with indexing and uniqueness.
✗ Incorrect
Adding UNIQUE constraint on Email creates an index that speeds up lookups and ensures no duplicate emails exist. VARCHAR(255) is appropriate for email length.