0
0
SQLquery~20 mins

Database design best practices in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Design Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use normalization in database design?
Which of the following best explains the main purpose of normalization in database design?
ATo increase the number of tables for faster queries
BTo store all data in a single table for simplicity
CTo reduce data redundancy and improve data integrity
DTo avoid using primary keys in tables
Attempts:
2 left
💡 Hint
Think about how normalization helps keep data consistent and organized.
query_result
intermediate
2:00remaining
Identify the correct foreign key relationship
Given two tables, Orders and Customers, which SQL statement correctly creates a foreign key from Orders to Customers?
SQL
CREATE TABLE Customers (
  CustomerID INT PRIMARY KEY,
  Name VARCHAR(100)
);

CREATE TABLE Orders (
  OrderID INT PRIMARY KEY,
  CustomerID INT,
  OrderDate DATE
);
AALTER TABLE Orders ADD FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID);
BALTER TABLE Customers ADD FOREIGN KEY (CustomerID) REFERENCES Orders(CustomerID);
CALTER TABLE Orders ADD FOREIGN KEY (OrderID) REFERENCES Customers(CustomerID);
DALTER TABLE Orders ADD FOREIGN KEY (CustomerID) REFERENCES Orders(OrderID);
Attempts:
2 left
💡 Hint
The foreign key should link the child table to the parent table's primary key.
📝 Syntax
advanced
1:30remaining
Find the syntax error in table creation
Which option contains a syntax error when creating a table with a primary key and a unique constraint?
SQL
CREATE TABLE Employees (
  EmployeeID INT PRIMARY KEY,
  Email VARCHAR(255) UNIQUE
);
ACREATE TABLE Employees (EmployeeID INT PRIMARY KEY, Email VARCHAR(255) UNIQUE);
BCREATE TABLE Employees (EmployeeID INT PRIMARY KEY, Email VARCHAR(255) UNIQUE NOT NULL);
CCREATE TABLE Employees (EmployeeID INT PRIMARY KEY, Email VARCHAR(255), UNIQUE (Email));
DCREATE TABLE Employees (EmployeeID INT PRIMARY KEY, Email VARCHAR(255) UNIQUE CONSTRAINT);
Attempts:
2 left
💡 Hint
Check the placement and usage of the UNIQUE keyword and CONSTRAINT keyword.
optimization
advanced
2:00remaining
Choose the best indexing strategy
You have a large table with millions of rows and frequent queries filtering by the column last_name. Which indexing strategy improves query speed without wasting much space?
ACreate a B-tree index on the last_name column
BCreate a full-text index on the last_name column
CCreate a unique index on the last_name column
DCreate no index and rely on sequential scans
Attempts:
2 left
💡 Hint
Think about the type of queries and the best index type for filtering by a column.
🔧 Debug
expert
2:30remaining
Identify the cause of data inconsistency
A database has two tables: Products and Orders. Sometimes, orders reference product IDs that do not exist in Products. What is the most likely cause?
AThe Orders table has a primary key on product ID
BThe foreign key constraint between Orders and Products is missing or disabled
CThe Products table uses a composite primary key
DThe primary key in Products is not unique
Attempts:
2 left
💡 Hint
Think about what enforces valid references between tables.