0
0
SQLquery~20 mins

CREATE TABLE syntax in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CREATE TABLE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this CREATE TABLE statement?
Consider the following SQL statement:
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);
AA new table named Employees is created with three columns: ID, Name, and Age. ID is the primary key.
BAn error occurs because VARCHAR requires a length greater than 50.
CThe statement creates a table named Employees but the Age column is not created due to missing datatype.
DThe table is created but without a primary key constraint.
Attempts:
2 left
💡 Hint
Think about what PRIMARY KEY means and if the syntax for VARCHAR is correct.
📝 Syntax
intermediate
2: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.
ACREATE TABLE Products (ProductID INT, ProductName VARCHAR(100), Price DECIMAL(10,2));
BCREATE TABLE Orders (OrderID INT PRIMARY KEY, OrderDate DATE, CustomerID INT);
CCREATE TABLE Customers (CustomerID INT, Name VARCHAR(50), Email VARCHAR(50) UNIQUE);
DCREATE TABLE Sales (SaleID INT, SaleDate DATETIME, Amount MONEY(10,2));
Attempts:
2 left
💡 Hint
Check the datatype MONEY and its parameters.
🧠 Conceptual
advanced
2: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.
AIt ensures that the column values are unique and not NULL, uniquely identifying each row.
BIt allows duplicate values but speeds up queries on that column.
CIt automatically creates an index but does not enforce uniqueness.
DIt marks the column as optional and allows NULL values.
Attempts:
2 left
💡 Hint
Think about what makes each row in a table unique.
🔧 Debug
advanced
2:00remaining
Why does this CREATE TABLE statement fail?
Examine this SQL statement:
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');
AThe table name Inventory is a reserved keyword and cannot be used.
BThe column Quantity is missing a NOT NULL constraint.
CThe DEFAULT value 'ten' is a string and cannot be assigned to an INT column.
DThe statement is valid and will create the table successfully.
Attempts:
2 left
💡 Hint
Check the data type of the DEFAULT value compared to the column type.
optimization
expert
3: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?
ACREATE TABLE Users (UserID INT PRIMARY KEY, Email TEXT, Name VARCHAR(100));
BCREATE TABLE Users (UserID INT PRIMARY KEY, Email VARCHAR(255) UNIQUE, Name VARCHAR(100));
CCREATE TABLE Users (UserID INT, Email VARCHAR(255), Name VARCHAR(100));
DCREATE TABLE Users (UserID INT PRIMARY KEY, Email VARCHAR(255), Name VARCHAR(100));
Attempts:
2 left
💡 Hint
Consider constraints that help with indexing and uniqueness.