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 Type | Example | Notes |
|---|---|---|
| Simple | name | Cannot be divided |
| Composite | FullName → FirstName, LastName | Can split into sub-parts |
| Derived | age (from dob) | Calculated from other attribute |
| Multi-valued | phone_numbers | Can have multiple values |
| Key Attribute | student_id | Uniquely 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.
| Type | Example | Description |
|---|---|---|
| One-to-One (1:1) | Employee – CompanyCar | Each employee has one car |
| One-to-Many (1:N) | Teacher – Students | One teacher teaches many students |
| Many-to-One (N:1) | Students – Department | Many students belong to one department |
| Many-to-Many (M:N) | Students – Courses | Students 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)
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ