SQL Dbms Btech Notes
SQL Dbms Btech Notes
**Main Components:**
- **Entity:** Object or concept, represented as a rectangle (e.g., Student, Course).
- **Attribute:** Property of entity, shown as an oval (e.g., name, roll_no).
- **Relationship:** Association between entities, represented by diamonds (e.g., Enrolls).
**Example:**
- A Student "enrolls" in a Course.
- Attributes: Student(ID, Name), Course(ID, Title)
**Design Issues:**
- **Use of derived attributes:** Prefer storing calculated values or deriving them on the fly?
- **Use of weak entities:** If entities cannot exist without another, use weak entities.
- **Multiple relationships:** Identify all possible associations.
- **Redundancy:** Minimize data repetition.
**Example:**
Superclass: Employee(emp_id, name)
Subclass: Engineer(emp_id, specialization)
**Example:**
- Specialization: Employee → Engineer, Manager
- Generalization: Car, Truck → Vehicle
**Example:**
- A "Person" can be a "Customer" or an "Employee".
- Category: "Person" ← {Customer, Employee}
**Key Concepts:**
- **Relation:** Table
- **Tuple:** Row
- **Attribute:** Column
- **Domain:** Set of allowed values
Relational Constraints
1. **Domain Constraint:** Each attribute must contain only values from a predefined
domain.
2. **Key Constraint:** Each table must have a primary key.
3. **Entity Integrity Constraint:** Primary key cannot be NULL.
4. **Referential Integrity Constraint:** Foreign key must match a primary key in another
table or be NULL.
Relational Algebra
A procedural query language used to retrieve data.
**Core Concepts:**
- Relation, tuple, attribute, domain
- Primary key, foreign key
- Schema = Structure of the database
- Instance = Current state of the database
**Constraints:**
- Domain, Key, Referential Integrity
- Ensures logical consistency
**Violations:**
- Insert with duplicate primary key → Key violation
- Insert child without parent → Referential violation
- Update changing type → Domain violation