0
0
DBMS Theoryknowledge~6 mins

Projection operation in DBMS Theory - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine you have a big table full of information, but you only want to see a few specific columns. The projection operation helps you pick just those columns you need from a database table, making the data easier to understand and use.
Explanation
Selecting Specific Columns
Projection focuses on choosing certain columns from a table while ignoring the rest. This lets you work with only the data you need without extra clutter. It is like filtering out unnecessary details to keep the important parts.
Projection extracts only the desired columns from a table.
Removing Duplicate Rows
When you project columns, sometimes the result may have repeated rows because different original rows share the same values in those columns. Projection removes these duplicates to give a clean list of unique rows.
Projection eliminates duplicate rows to show unique results.
Relation to Query Languages
In query languages like SQL, projection is done using the SELECT statement to specify which columns to retrieve. This operation is fundamental for querying databases efficiently and clearly.
Projection is implemented by specifying columns in database queries.
Effect on Data Structure
Projection changes the shape of the data by reducing the number of columns but keeps the number of rows after duplicates are removed. This helps in focusing analysis on relevant attributes.
Projection reduces columns but maintains unique rows.
Real World Analogy

Imagine you have a large photo album with many pictures, but you want to create a smaller album showing only the faces of people. You cut out just the faces from each photo and paste them into a new album, ignoring the backgrounds and other details.

Selecting Specific Columns → Cutting out only the faces from each photo
Removing Duplicate Rows → Avoiding pasting the same face multiple times in the new album
Relation to Query Languages → Choosing which parts of photos to cut out when making the new album
Effect on Data Structure → Making the album smaller by showing fewer details but keeping all unique faces
Diagram
Diagram
┌───────────────┐
│ Original Table│
│───────────────│
│ ID │ Name │ Age│
│ 1  │ Anna │ 25 │
│ 2  │ Bob  │ 30 │
│ 3  │ Anna │ 25 │
└────┴──────┴────┘
       ↓ Projection (select Name)
┌───────────────┐
│ Projected Set │
│───────────────│
│ Name          │
│ Anna          │
│ Bob           │
└───────────────┘
This diagram shows how projection selects the 'Name' column from a table and removes duplicate rows.
Key Facts
ProjectionAn operation that selects specific columns from a database table.
Duplicate RemovalProjection removes duplicate rows to keep only unique results.
SELECT StatementThe SQL command used to perform projection by specifying columns.
Result ShapeProjection reduces the number of columns but keeps unique rows.
Code Example
DBMS Theory
import sqlite3

conn = sqlite3.connect(':memory:')
cur = conn.cursor()
cur.execute('CREATE TABLE people (id INTEGER, name TEXT, age INTEGER)')
cur.execute("INSERT INTO people VALUES (1, 'Anna', 25)")
cur.execute("INSERT INTO people VALUES (2, 'Bob', 30)")
cur.execute("INSERT INTO people VALUES (3, 'Anna', 25)")

cur.execute('SELECT DISTINCT name FROM people')
for row in cur.fetchall():
    print(row[0])
OutputSuccess
Common Confusions
Projection changes the number of rows in the table arbitrarily.
Projection changes the number of rows in the table arbitrarily. Projection only removes duplicate rows caused by selecting fewer columns; it does not randomly change row count.
Projection modifies the original table data.
Projection modifies the original table data. Projection creates a new result set without altering the original table.
Projection is the same as filtering rows.
Projection is the same as filtering rows. Projection selects columns, while filtering (selection) chooses rows based on conditions.
Summary
Projection lets you pick specific columns from a table to focus on relevant data.
It removes duplicate rows that appear when only some columns are selected.
Projection is done in SQL using the SELECT statement with specified columns.