Database Engineering
  • Need of Database
  • Database and Database Management System
  • What is Relational Database Model ?
  • Installing Postgresql
    • Installing PostgreSQL on Linux
    • Installing PostgreSQL on Windows
    • Installing PostgreSQL on Mac
    • Postgres in Docker
  • What happens during the initial installation ?
    • Roles, Users & Groups
    • More examples on Roles
  • Sample Databases
    • DVD Rental Database
  • Querying Data
    • SELECT Query
    • Column Aliases
    • Order By
    • SELECT DISTINCT
    • DB-TASK-001
  • Filtering Data
    • WHERE ?
    • AND Operator
    • OR Operator
    • LIMIT
    • FETCH
    • IN
    • BETWEEN
    • LIKE
    • SIMILAR TO
    • IS NULL
    • ESCAPE
    • DB-TASK-002
  • Entity Relationship Diagram
    • What is an ER Diagram ?
    • Entity
    • Identifiers
    • Relationship
    • Attributes
    • Cardinality
    • Entity Relationship Diagram Tutorial
    • DB-TASK-003
  • Joins
    • Joins
    • Joins With Employee and Departments
  • Joins on E-Commerce
Powered by GitBook
On this page
  • 1. Simple Attribute
  • 2. Composite Attribute
  • 3. Derived Attribute
  • 4. Multivalued Attribute
  • 5. Key Attribute
  • Summary
  1. Entity Relationship Diagram

Attributes

PreviousRelationshipNextCardinality

Last updated 5 months ago

Attributes are the properties or characteristics of an entity in a database. They represent the data stored about the entity and are implemented as columns in a table. Graphically represented as ovals or circles.

Here are examples of different types of attributes with explanations,

1. Simple Attribute

  • Definition: Cannot be divided into smaller parts.

  • Example:

    • Entity: Student

    • Attributes: StudentID, Name, Age

    • Explanation: StudentID is a simple, indivisible identifier for a student.

Table Example

CREATE TABLE Student (
    StudentID SERIAL PRIMARY KEY,
    Name TEXT NOT NULL,
    Age INT
);

2. Composite Attribute

  • Definition: Can be divided into smaller sub-parts, each with independent meaning.

  • Example:

    • Entity: Student

    • Attribute: FullName (composed of FirstName and LastName)

    • Explanation: FullName can be divided into FirstName and LastName.

Table Example

CREATE TABLE Student (
    StudentID SERIAL PRIMARY KEY,
    FirstName TEXT NOT NULL,
    LastName TEXT NOT NULL
);

3. Derived Attribute

  • Definition: Can be calculated from other attributes.

  • Example:

    • Entity: Employee

    • Attributes: DateOfBirth, Age

    • Explanation: Age is derived from DateOfBirth.

Table Example

CREATE TABLE Employee (
    EmployeeID SERIAL PRIMARY KEY,
    Name TEXT NOT NULL,
    DateOfBirth DATE
);
-- Age can be calculated as:
-- SELECT DATE_PART('year', AGE(DateOfBirth)) AS Age FROM Employee;

4. Multivalued Attribute

  • Definition: Can have more than one value for a single entity.

  • Example:

    • Entity: Student

    • Attribute: PhoneNumbers (a student may have multiple phone numbers)

    • Explanation: A student can have a home phone and a mobile phone.

Table Example

To handle multivalued attributes, we use a separate table

CREATE TABLE Student (
    StudentID SERIAL PRIMARY KEY,
    Name TEXT NOT NULL
);

CREATE TABLE StudentPhone (
    StudentID INT REFERENCES Student(StudentID),
    PhoneNumber TEXT NOT NULL
);

5. Key Attribute

  • Definition: Uniquely identifies an entity in a table.

  • Example:

    • Entity: Student

    • Attribute: StudentID

    • Explanation: StudentID is a unique identifier for each student.

Table Example

CREATE TABLE Student (
    StudentID SERIAL PRIMARY KEY,
    Name TEXT NOT NULL
);

Summary

Type

Description

Example

Simple

Cannot be divided further.

Name, Age

Composite

Can be divided into sub-parts.

FullName → FirstName, LastName

Derived

Calculated from other attributes.

Age from DateOfBirth

Multivalued

Can have multiple values for one entity.

PhoneNumbers

Key

Uniquely identifies an entity.

StudentID

Foreign Key

References the primary key of another entity.

StudentID in Enrollment table