Bird
Raised Fist0
Hadoopdata~20 mins

Creating databases and tables in Hadoop - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Hive Database and Table Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Hive query?
Consider the following Hive query to create a database and then list all databases. What will be the output of the SHOW DATABASES; command?
Hadoop
CREATE DATABASE IF NOT EXISTS sales_db;
SHOW DATABASES;
A["default"]
B["default", "sales_db"]
CSyntaxError
D[]
Attempts:
2 left
💡 Hint
Think about what databases exist by default and what happens when you create a new one.
❓ data_output
intermediate
2:00remaining
How many tables are in the database after these commands?
Given the following Hive commands, how many tables will be listed in sales_db?
Hadoop
CREATE DATABASE IF NOT EXISTS sales_db;
USE sales_db;
CREATE TABLE IF NOT EXISTS customers (id INT, name STRING);
CREATE TABLE IF NOT EXISTS orders (order_id INT, customer_id INT);
SHOW TABLES;
ASyntaxError
B0
C1
D2
Attempts:
2 left
💡 Hint
Count how many tables you created in the database.
🔧 Debug
advanced
2:00remaining
Identify the error in this Hive table creation command
What error will this Hive query produce?
Hadoop
CREATE TABLE employees (id INT, name STRING, salary);
ASyntaxError: Missing data type for column 'salary'
BNo error, table created successfully
CTypeError: Invalid column name
DRuntimeError: Table already exists
Attempts:
2 left
💡 Hint
Check if all columns have data types specified.
🧠 Conceptual
advanced
2:00remaining
What is the difference between EXTERNAL and MANAGED tables in Hive?
Choose the correct statement about EXTERNAL and MANAGED tables in Hive.
ADropping a MANAGED table deletes both metadata and data; dropping an EXTERNAL table deletes only metadata.
BDropping an EXTERNAL table deletes both metadata and data; dropping a MANAGED table deletes only metadata.
CBoth EXTERNAL and MANAGED tables delete data when dropped.
DNeither EXTERNAL nor MANAGED tables delete data when dropped.
Attempts:
2 left
💡 Hint
Think about who manages the data files for each table type.
🚀 Application
expert
3:00remaining
Which command creates a partitioned table in Hive?
You want to create a table named sales partitioned by year and month. Which Hive command correctly creates this partitioned table?
ACREATE TABLE sales PARTITIONED BY (year INT, month INT) (id INT, amount FLOAT);
BCREATE TABLE sales (id INT, amount FLOAT, year INT, month INT) PARTITIONED BY ();
CCREATE TABLE sales (id INT, amount FLOAT) PARTITIONED BY (year INT, month INT);
DCREATE TABLE sales (id INT, amount FLOAT) PARTITION (year INT, month INT);
Attempts:
2 left
💡 Hint
Remember the syntax for partitioned tables in Hive: columns go first, then PARTITIONED BY clause.

Practice

(1/5)
1. What is the main purpose of creating a database in Hadoop?
easy
A. To run queries faster
B. To store data in rows and columns
C. To organize data into separate groups
D. To delete old data automatically

Solution

  1. Step 1: Understand the role of a database

    A database is used to organize data logically into separate groups or collections.
  2. Step 2: Differentiate database from tables

    Tables store data in rows and columns inside a database, but the database itself is for grouping.
  3. Final Answer:

    To organize data into separate groups -> Option C
  4. Quick Check:

    Database = Organize data groups [OK]
Hint: Databases group data; tables hold the data [OK]
Common Mistakes:
  • Confusing database with table
  • Thinking database stores data directly
  • Assuming database speeds up queries automatically
2. Which of the following is the correct syntax to create a database named sales_db in Hive?
easy
A. CREATE DATABASE sales_db;
B. MAKE DATABASE sales_db;
C. CREATE DB sales_db;
D. NEW DATABASE sales_db;

Solution

  1. Step 1: Recall Hive syntax for database creation

    The correct command to create a database in Hive is CREATE DATABASE database_name;.
  2. Step 2: Check each option

    Only CREATE DATABASE sales_db; matches the correct syntax exactly.
  3. Final Answer:

    CREATE DATABASE sales_db; -> Option A
  4. Quick Check:

    CREATE DATABASE = correct syntax [OK]
Hint: Use CREATE DATABASE, not MAKE or NEW [OK]
Common Mistakes:
  • Using MAKE or NEW instead of CREATE
  • Abbreviating DATABASE as DB
  • Missing semicolon at end
3. What will be the result of running this Hive query?
CREATE TABLE employees (id INT, name STRING, salary FLOAT);
medium
A. Creates a table named employees with three columns
B. Throws a syntax error due to missing database name
C. Creates a database named employees
D. Creates a table with no columns

Solution

  1. Step 1: Analyze the CREATE TABLE statement

    The query uses correct syntax to create a table named employees with columns id, name, and salary.
  2. Step 2: Check for errors or missing parts

    Database name is optional if default database is used; no syntax error here.
  3. Final Answer:

    Creates a table named employees with three columns -> Option A
  4. Quick Check:

    CREATE TABLE with columns = creates table [OK]
Hint: CREATE TABLE defines columns inside parentheses [OK]
Common Mistakes:
  • Thinking database name is mandatory
  • Confusing table and database creation
  • Assuming syntax error without checking carefully
4. Identify the error in this Hive query:
CREATE TABLE users id INT, name STRING;
medium
A. Table name is invalid
B. Missing parentheses around column definitions
C. Data types are incorrect
D. CREATE TABLE keyword is misspelled

Solution

  1. Step 1: Review the syntax for CREATE TABLE

    Column definitions must be enclosed in parentheses after the table name.
  2. Step 2: Check the given query

    The query misses parentheses around id INT, name STRING, causing syntax error.
  3. Final Answer:

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

    Columns need parentheses [OK]
Hint: Always use parentheses for columns in CREATE TABLE [OK]
Common Mistakes:
  • Forgetting parentheses
  • Assuming table name is wrong
  • Thinking data types are invalid
5. You want to create a database company_db and inside it a table departments with columns dept_id INT and dept_name STRING. Which sequence of commands is correct?
hard
A. CREATE TABLE company_db.departments (dept_id INT, dept_name STRING);
B. CREATE DATABASE company_db; CREATE TABLE departments dept_id INT, dept_name STRING;
C. USE company_db; CREATE DATABASE company_db; CREATE TABLE departments (dept_id INT, dept_name STRING);
D. CREATE DATABASE company_db; USE company_db; CREATE TABLE departments (dept_id INT, dept_name STRING);

Solution

  1. Step 1: Create the database first

    Use CREATE DATABASE company_db; to make the database.
  2. Step 2: Switch to the new database

    Use USE company_db; to set the context for table creation.
  3. Step 3: Create the table with correct syntax

    Use CREATE TABLE departments (dept_id INT, dept_name STRING); inside the database.
  4. Final Answer:

    CREATE DATABASE company_db; USE company_db; CREATE TABLE departments (dept_id INT, dept_name STRING); -> Option D
  5. Quick Check:

    Create DB, switch DB, then create table [OK]
Hint: Create DB, then USE it before creating tables [OK]
Common Mistakes:
  • Trying to create table before database
  • Wrong order of USE and CREATE DATABASE
  • Missing parentheses in CREATE TABLE
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