🏷️ Entity, Attributes, and Relationships in DBMS with Oracle Examples

Entity, Attributes, and Relationships in DBMS

Detailed explanation with examples and Oracle SQL for database design.

1. Entity

An entity is a real-world object or concept with identifiable data.

  • Examples: Student, Course, Teacher

Types of Entities

  • Strong Entity: Exists independently, has primary key.
    Example: Student(student_id, name, dob, course)
  • Weak Entity: Depends on another entity, no primary key of its own.
    Example: Dependent(dep_id, name, emp_id)

2. Attributes

Attributes are properties or characteristics of an entity.

Attribute TypeExampleNotes
SimplenameCannot be divided
CompositeFullName → FirstName, LastNameCan split into sub-parts
Derivedage (from dob)Calculated from other attribute
Multi-valuedphone_numbersCan have multiple values
Key Attributestudent_idUniquely identifies entity

Oracle Table Example

CREATE TABLE Student (
    student_id NUMBER PRIMARY KEY,
    first_name VARCHAR2(50),
    last_name VARCHAR2(50),
    dob DATE,
    course VARCHAR2(50)
);

3. Relationships

A relationship represents how entities are associated.

TypeExampleDescription
One-to-One (1:1)Employee – CompanyCarEach employee has one car
One-to-Many (1:N)Teacher – StudentsOne teacher teaches many students
Many-to-One (N:1)Students – DepartmentMany students belong to one department
Many-to-Many (M:N)Students – CoursesStudents enroll in multiple courses; each course has many students

Oracle Example for Many-to-Many Relationship

-- Student Table
CREATE TABLE Student (
    student_id NUMBER PRIMARY KEY,
    name VARCHAR2(50)
);

-- Course Table
CREATE TABLE Course (
    course_id NUMBER PRIMARY KEY,
    course_name VARCHAR2(50)
);

-- Enrollment Table (Relationship)
CREATE TABLE Enrollment (
    student_id NUMBER,
    course_id NUMBER,
    PRIMARY KEY(student_id, course_id),
    FOREIGN KEY(student_id) REFERENCES Student(student_id),
    FOREIGN KEY(course_id) REFERENCES Course(course_id)
);

4. Summary

  • Entity: Student, Teacher, Course (real-world object)
  • Attribute: Properties like student_id, name, dob
  • Relationship: How entities are connected (1:1, 1:N, N:1, M:N)
Entity, Attributes, Relationships, DBMS, ER diagram, Oracle SQL, Strong Entity, Weak Entity, One-to-One, One-to-Many, Many-to-Many, database design tutorial

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ