Bird
Raised Fist0
DBMS Theoryknowledge~10 mins

Projection operation in DBMS Theory - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Projection operation
Start with a Table
↓
Select Columns to Keep
↓
Remove Other Columns
↓
Create New Table with Selected Columns
↓
Result: Table with Only Chosen Columns
Projection operation takes a table and creates a new table with only the selected columns, removing all others.
Execution Sample
DBMS Theory
Table: Students(ID, Name, Age, Grade)
Projection: Select columns Name, Grade
Result: Table with columns Name, Grade only
This operation extracts only the Name and Grade columns from the Students table.
Analysis Table
StepInput Table ColumnsColumns SelectedActionOutput Table Columns
1ID, Name, Age, GradeName, GradeIdentify columns to keepName, Grade
2ID, Name, Age, GradeName, GradeRemove columns ID, AgeName, Grade
3N/AN/ACreate new table with selected columnsName, Grade
💡 Projection complete: only selected columns remain in the output table.
State Tracker
VariableStartAfter Step 1After Step 2Final
Input Table ColumnsID, Name, Age, GradeID, Name, Age, GradeID, Name, Age, GradeN/A
Selected ColumnsN/AName, GradeName, GradeName, Grade
Output Table ColumnsN/AN/AN/AName, Grade
Key Insights - 2 Insights
Why do we remove columns instead of just copying the whole table?
Because projection only keeps the selected columns, removing others to focus on needed data, as shown in execution_table rows 2 and 3.
Does projection change the number of rows in the table?
No, projection keeps all rows but only changes which columns are shown, as seen in the output table columns staying the same in number of rows.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what columns remain after Step 2?
AID, Name, Age, Grade
BID, Age
CName, Grade
DNo columns remain
💡 Hint
Check the 'Output Table Columns' column in row for Step 2 in execution_table.
At which step is the new table with only selected columns created?
AStep 3
BStep 2
CStep 1
DProjection does not create a new table
💡 Hint
Look at the 'Action' column in execution_table to find when the new table is created.
If we select columns ID and Age instead, what would be the output columns after Step 3?
AName, Grade
BID, Age
CID, Name, Age, Grade
DNo columns
💡 Hint
Refer to variable_tracker for how selected columns affect output columns.
Concept Snapshot
Projection operation:
- Select specific columns from a table
- Remove all other columns
- Keep all rows unchanged
- Result is a new table with only chosen columns
- Used to focus on needed data fields
Full Transcript
Projection operation in databases means selecting certain columns from a table and creating a new table with only those columns. The process starts with the original table, then identifies which columns to keep, removes the rest, and finally outputs a new table with only the selected columns. The number of rows stays the same, only columns change. This helps focus on relevant data without altering the original table structure.

Practice

(1/5)
1. What does the projection operation in a database primarily do?
easy
A. Select specific columns from a table
B. Combine rows from two tables
C. Delete rows from a table
D. Sort rows in ascending order

Solution

  1. Step 1: Understand the purpose of projection

    Projection is used to choose certain columns from a table, not rows or sorting.
  2. Step 2: Compare options with definition

    Only Select specific columns from a table matches the definition of projection as selecting columns.
  3. Final Answer:

    Select specific columns from a table -> Option A
  4. Quick Check:

    Projection = Selecting columns [OK]
Hint: Projection means picking columns only, not rows or sorting [OK]
Common Mistakes:
  • Confusing projection with selection (which filters rows)
  • Thinking projection changes row order
  • Mixing projection with join operations
2. Which of the following is the correct SQL syntax for projection to get columns name and age from a table students?
easy
A. SELECT * FROM students WHERE name, age;
B. SELECT name age FROM students;
C. SELECT name AND age FROM students;
D. SELECT name, age FROM students;

Solution

  1. Step 1: Recall correct SELECT syntax

    The correct syntax uses SELECT followed by column names separated by commas, then FROM table.
  2. Step 2: Check each option

    SELECT name, age FROM students; matches the correct syntax: SELECT name, age FROM students;
  3. Final Answer:

    SELECT name, age FROM students; -> Option D
  4. Quick Check:

    Correct SELECT syntax = SELECT name, age FROM students; [OK]
Hint: Use commas between columns after SELECT, then FROM table [OK]
Common Mistakes:
  • Using * instead of column names for projection
  • Using AND instead of comma between columns
  • Omitting commas between column names
3. Given a table employees with columns id, name, and salary, what will the result of SELECT name FROM employees; be?
medium
A. All rows with only the name column values
B. All rows with id and name columns
C. All rows with all columns
D. Only the first row with name column

Solution

  1. Step 1: Understand the SELECT statement

    SELECT name FROM employees returns all rows but only the 'name' column values.
  2. Step 2: Compare options with expected output

    All rows with only the name column values correctly describes the output as all rows with only the 'name' column.
  3. Final Answer:

    All rows with only the name column values -> Option A
  4. Quick Check:

    Projection selects columns, so only 'name' column shown [OK]
Hint: SELECT column returns all rows but only that column [OK]
Common Mistakes:
  • Thinking it returns only one row
  • Expecting multiple columns without listing them
  • Confusing projection with filtering rows
4. Identify the error in this SQL query for projection: SELECT name age FROM employees;
medium
A. SELECT keyword is misspelled
B. Table name is incorrect
C. Missing comma between column names
D. No error, query is correct

Solution

  1. Step 1: Analyze the column list syntax

    Column names must be separated by commas in SELECT statements.
  2. Step 2: Check the given query

    The query has 'name age' without a comma, which is a syntax error.
  3. Final Answer:

    Missing comma between column names -> Option C
  4. Quick Check:

    Columns need commas between them [OK]
Hint: Always separate columns with commas in SELECT [OK]
Common Mistakes:
  • Forgetting commas between columns
  • Assuming space works as separator
  • Ignoring syntax errors in column list
5. You have a table orders with columns order_id, customer_id, product, and quantity. You want to create a new table order_summary that only stores order_id and quantity. Which SQL statement correctly uses projection to do this?
hard
A. CREATE TABLE order_summary SELECT * FROM orders;
B. CREATE TABLE order_summary AS SELECT order_id, quantity FROM orders;
C. INSERT INTO order_summary SELECT customer_id, product FROM orders;
D. CREATE order_summary AS SELECT order_id, quantity FROM orders;

Solution

  1. Step 1: Understand creating a new table with selected columns

    To create a new table with specific columns, use CREATE TABLE ... AS SELECT with projection.
  2. Step 2: Evaluate each option

    CREATE TABLE order_summary AS SELECT order_id, quantity FROM orders; correctly creates the table with only order_id and quantity columns from orders.
  3. Final Answer:

    CREATE TABLE order_summary AS SELECT order_id, quantity FROM orders; -> Option B
  4. Quick Check:

    Projection + CREATE TABLE AS SELECT = CREATE TABLE order_summary AS SELECT order_id, quantity FROM orders; [OK]
Hint: Use CREATE TABLE ... AS SELECT columns for projection [OK]
Common Mistakes:
  • Using SELECT * instead of specific columns
  • Omitting CREATE TABLE keyword
  • Selecting wrong columns for the new 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