Bird
Raised Fist0
SQLquery~20 mins

CREATE TABLE syntax in SQL - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What does the CREATE TABLE statement do in SQL?
easy
A. It deletes an existing table.
B. It selects data from a table.
C. It updates data inside a table.
D. It creates a new table in the database.

Solution

  1. Step 1: Understand the purpose of CREATE TABLE

    The CREATE TABLE command is used to make a new table to store data in a database.
  2. Step 2: Compare with other SQL commands

    Deleting, updating, or selecting data are done by other commands like DROP, UPDATE, and SELECT.
  3. Final Answer:

    It creates a new table in the database. -> Option D
  4. Quick Check:

    CREATE TABLE = create new table [OK]
Hint: Remember: CREATE TABLE makes new tables [OK]
Common Mistakes:
  • Confusing CREATE with DROP or SELECT
  • Thinking CREATE modifies data inside tables
  • Mixing CREATE TABLE with UPDATE command
2. Which of the following is the correct syntax to create a table named Students with columns id (integer) and name (text)?
easy
A. CREATE TABLE Students (id INT, name TEXT);
B. CREATE Students TABLE (id INT, name TEXT);
C. CREATE TABLE Students id INT, name TEXT;
D. CREATE TABLE Students {id INT, name TEXT};

Solution

  1. Step 1: Check the correct order of keywords

    The correct order is CREATE TABLE table_name (columns);. CREATE TABLE Students (id INT, name TEXT); follows this.
  2. Step 2: Verify column definitions and punctuation

    Columns must be inside parentheses and separated by commas. CREATE TABLE Students (id INT, name TEXT); uses parentheses and commas correctly.
  3. Final Answer:

    CREATE TABLE Students (id INT, name TEXT); -> Option A
  4. Quick Check:

    CREATE TABLE + (columns) syntax = CREATE TABLE Students (id INT, name TEXT); [OK]
Hint: Use parentheses around columns after table name [OK]
Common Mistakes:
  • Placing TABLE keyword after table name
  • Missing parentheses around columns
  • Using curly braces instead of parentheses
3. What will happen if you run this SQL statement?
CREATE TABLE Employees (emp_id INT PRIMARY KEY, emp_name VARCHAR(50));
medium
A. Creates a table Employees with emp_id as unique key and emp_name as text.
B. Creates a table Employees but emp_id is not unique.
C. Syntax error because VARCHAR is not allowed.
D. Creates a table Employees but emp_name cannot store text.

Solution

  1. Step 1: Understand column definitions

    The statement defines emp_id as an integer and sets it as PRIMARY KEY, which means it must be unique.
  2. Step 2: Check data types and constraints

    VARCHAR(50) is a valid type for text up to 50 characters. So emp_name can store text.
  3. Final Answer:

    Creates a table Employees with emp_id as unique key and emp_name as text. -> Option A
  4. Quick Check:

    PRIMARY KEY = unique key, VARCHAR = text [OK]
Hint: PRIMARY KEY means unique; VARCHAR stores text [OK]
Common Mistakes:
  • Thinking VARCHAR is invalid
  • Assuming PRIMARY KEY allows duplicates
  • Confusing data types with constraints
4. Identify the error in this SQL statement:
CREATE TABLE Orders order_id INT, order_date DATE;
medium
A. Incorrect data type for order_date.
B. Missing parentheses around column definitions.
C. Table name cannot be Orders.
D. Missing semicolon at the end.

Solution

  1. Step 1: Check syntax for column definitions

    Column names and types must be inside parentheses after the table name.
  2. Step 2: Verify other parts

    Data types and table name are valid, and semicolon is present.
  3. Final Answer:

    Missing parentheses around column definitions. -> Option B
  4. Quick Check:

    Columns must be inside ( ) [OK]
Hint: Always use parentheses around columns in CREATE TABLE [OK]
Common Mistakes:
  • Omitting parentheses around columns
  • Using wrong data types without error
  • Confusing table name rules
5. You want to create a table Products with columns product_id (integer, unique), product_name (text), and price (decimal). Which SQL statement correctly enforces uniqueness on product_id using PRIMARY KEY?
hard
A. CREATE TABLE Products (product_id INT UNIQUE, product_name TEXT, price DECIMAL);
B. CREATE TABLE Products (product_id INT, product_name TEXT, price DECIMAL UNIQUE);
C. CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL);
D. CREATE TABLE Products (product_id INT, product_name TEXT UNIQUE, price DECIMAL);

Solution

  1. Step 1: Understand uniqueness constraints

    Both UNIQUE and PRIMARY KEY enforce uniqueness, but PRIMARY KEY also disallows NULLs and is preferred for IDs.
  2. Step 2: Analyze options for correct uniqueness on product_id

    CREATE TABLE Products (product_id INT UNIQUE, product_name TEXT, price DECIMAL); uses UNIQUE on product_id, which works but PRIMARY KEY is better. CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL); uses PRIMARY KEY on product_id, which is the best practice.
  3. Final Answer:

    CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL); -> Option C
  4. Quick Check:

    PRIMARY KEY = unique + not null [OK]
Hint: Use PRIMARY KEY for unique IDs [OK]
Common Mistakes:
  • Putting UNIQUE on wrong column
  • Confusing UNIQUE with PRIMARY KEY
  • Not enforcing uniqueness on ID column
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard