📖 Scenario: You are managing a small library database. You need to create a table to store book information, then update the table structure, and finally remove the table when it is no longer needed.
🎯 Goal: Build SQL commands step-by-step to create a table, alter it by adding a new column, and then drop the table.
📋 What You'll Learn
Create a table named Books with columns BookID (integer, primary key) and Title (varchar(100))
Add a new column Author (varchar(100)) to the Books table
Drop the Books table
💡 Why This Matters
🌍 Real World
Database administrators and developers use DDL commands to set up and modify database structures for applications like libraries, stores, or websites.
💼 Career
Knowing how to create, alter, and drop tables is essential for roles involving database management, backend development, and data engineering.
Progress0 / 4 steps
1
Create the Books table
Write a SQL CREATE TABLE statement to create a table called Books with two columns: BookID as an integer primary key, and Title as a varchar of length 100.
DBMS Theory
Hint
Use CREATE TABLE Books (BookID INT PRIMARY KEY, Title VARCHAR(100)); to create the table.
2
Add Author column
Write a SQL ALTER TABLE statement to add a new column called Author with type varchar(100) to the existing Books table.
DBMS Theory
Hint
Use ALTER TABLE Books ADD Author VARCHAR(100); to add the new column.
3
Drop the Books table
Write a SQL DROP TABLE statement to remove the Books table from the database.
DBMS Theory
Hint
Use DROP TABLE Books; to delete the table.
4
Review and finalize DDL commands
Ensure your SQL script includes the CREATE TABLE statement for Books, the ALTER TABLE statement adding the Author column, and the DROP TABLE statement to remove the table.
DBMS Theory
Hint
Make sure all three statements are present and correctly written.
Practice
(1/5)
1. What does the CREATE statement do in a database?
easy
A. It makes a new table to store data.
B. It deletes an existing table and its data.
C. It changes the data inside a table.
D. It backs up the database.
Solution
Step 1: Understand the purpose of CREATE
The CREATE statement is used to make new database objects, such as tables, to store data.
Step 2: Compare with other statements
DROP deletes tables, ALTER changes structure, but CREATE makes new tables.
Final Answer:
It makes a new table to store data. -> Option A
Quick Check:
CREATE = Make new table [OK]
Hint: CREATE always makes new tables, not deletes or changes [OK]
Common Mistakes:
Confusing CREATE with DROP which deletes tables
Thinking CREATE changes existing data
Assuming CREATE backs up data
2. Which of the following is the correct syntax to add a new column named age of type INT to an existing table students?
easy
A. ALTER students ADD age INT;
B. ALTER TABLE students ADD COLUMN age INT;
C. DROP TABLE students ADD age INT;
D. CREATE TABLE students ADD age INT;
Solution
Step 1: Identify correct ALTER syntax
The correct syntax to add a column is: ALTER TABLE table_name ADD COLUMN column_name datatype;
Step 2: Check each option
ALTER TABLE students ADD COLUMN age INT; matches the correct syntax. Options B and C misuse CREATE and DROP. ALTER students ADD age INT; misses TABLE keyword.
Final Answer:
ALTER TABLE students ADD COLUMN age INT; -> Option B
Quick Check:
ALTER TABLE + ADD COLUMN = ALTER TABLE students ADD COLUMN age INT; [OK]
Hint: ALTER TABLE ... ADD COLUMN ... is the correct form [OK]
Common Mistakes:
Omitting TABLE keyword after ALTER
Using CREATE or DROP instead of ALTER
Forgetting the COLUMN keyword (optional but clearer)
3. Consider the following SQL commands executed in order: CREATE TABLE employees (id INT, name VARCHAR(50)); ALTER TABLE employees ADD COLUMN salary INT; What will be the structure of the employees table after these commands?
medium
A. Table with columns: id, name, salary
B. Table with columns: id, salary
C. Table with columns: id, name
D. Table with columns: name, salary
Solution
Step 1: Analyze CREATE TABLE command
The first command creates a table named employees with columns id and name.
Step 2: Analyze ALTER TABLE command
The second command adds a new column salary to the employees table.
Final Answer:
Table with columns: id, name, salary -> Option A
Quick Check:
CREATE + ALTER ADD COLUMN = id, name, salary [OK]
Hint: ALTER ADD COLUMN adds new columns to existing tables [OK]
Common Mistakes:
Ignoring the ALTER command effect
Assuming DROP was used to remove columns
Thinking ALTER replaces columns instead of adding
4. Identify the error in the following SQL statement: ALTER TABLE employees DROP salary;
medium
A. Table name is incorrect
B. DROP cannot be used with ALTER TABLE
C. Missing COLUMN keyword after DROP
D. salary column does not exist
Solution
Step 1: Understand DROP syntax in ALTER TABLE
To remove a column, syntax requires: ALTER TABLE table_name DROP COLUMN column_name;
Step 2: Check the given statement
The statement misses the COLUMN keyword after DROP, causing syntax error.
Final Answer:
Missing COLUMN keyword after DROP -> Option C
Quick Check:
ALTER TABLE DROP COLUMN required [OK]
Hint: DROP COLUMN must be used, not just DROP [OK]
Common Mistakes:
Omitting COLUMN keyword after DROP
Confusing DROP TABLE with DROP COLUMN
Assuming DROP alone removes columns
5. You want to permanently delete a table named orders and all its data from the database. Which SQL command should you use?
hard
A. ALTER TABLE orders DELETE;
B. ALTER TABLE orders DROP;
C. CREATE TABLE orders;
D. DROP TABLE orders;
Solution
Step 1: Understand the purpose of DROP TABLE
DROP TABLE deletes the entire table and its data permanently from the database.
Step 2: Evaluate the options
DROP TABLE orders; uses correct syntax. ALTER TABLE orders DROP; and D misuse ALTER. CREATE TABLE orders; creates a table instead of deleting.
Final Answer:
DROP TABLE orders; -> Option D
Quick Check:
DROP TABLE = delete table permanently [OK]
Hint: Use DROP TABLE to delete tables permanently [OK]
Common Mistakes:
Using ALTER instead of DROP to delete tables
Confusing CREATE with DROP
Omitting TABLE keyword in DROP statement
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.