0% found this document useful (0 votes)
12 views36 pages

DBMS - NOTES - (Selected Topics)

The document provides an overview of Database Management Systems (DBMS), including their definition, types (Hierarchical, Network, Relational, Object-Oriented), advantages, and disadvantages. It also discusses Flat File Systems, ER Diagrams, types of keys in SQL, the role of Database Administrators (DBAs), relational algebra, normalization, generalization, and specialization in database design. Each section outlines key concepts, examples, and the significance of these elements in managing and organizing data efficiently.

Uploaded by

Yash Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views36 pages

DBMS - NOTES - (Selected Topics)

The document provides an overview of Database Management Systems (DBMS), including their definition, types (Hierarchical, Network, Relational, Object-Oriented), advantages, and disadvantages. It also discusses Flat File Systems, ER Diagrams, types of keys in SQL, the role of Database Administrators (DBAs), relational algebra, normalization, generalization, and specialization in database design. Each section outlines key concepts, examples, and the significance of these elements in managing and organizing data efficiently.

Uploaded by

Yash Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

1.

DBMS (Definition, Types, Advantages & Disadvantages)

Definition

A Database Management System (DBMS) is software that enables users to store,


retrieve, manage, and manipulate data efficiently. It provides an interface between the
database and the users or applications, ensuring data integrity, security, and
consistency.

Types of DBMS

DBMS can be classified into four main types:

1. Hierarchical DBMS

o Data is organized in a tree-like structure with parent-child relationships.

o Example: IBM Information Management System (IMS).

2. Network DBMS

o Uses a graph structure where multiple records can be linked to multiple


records.

o Example: Integrated Data Store (IDS).

3. Relational DBMS (RDBMS)

o Stores data in tables with rows and columns using structured query
language (SQL).

o Example: MySQL, PostgreSQL, Oracle DB.

4. Object-Oriented DBMS (OODBMS)

o Stores data as objects, similar to object-oriented programming concepts.

o Example: MongoDB, ObjectDB.

Advantages of DBMS

� Data Integrity & Accuracy – Ensures data consistency and accuracy.


� Data Security – Provides access control mechanisms to prevent unauthorized
access.
� Data Redundancy Reduction – Eliminates duplicate data storage.
� Data Independence – Separates data structure from application logic.
� Multi-User Access – Allows multiple users to access data simultaneously.
� Backup & Recovery – Facilitates data recovery in case of failures.

Disadvantages of DBMS

� High Cost – Requires significant investment in hardware, software, and


maintenance.
� Complexity – Managing and setting up a DBMS requires expertise.
� Performance Issues – Large-scale databases may slow down performance.
� Risk of Data Loss – If not properly backed up, database crashes can lead to data
loss.

--------------------------------------------------------------------------------------------------------------

2. Flat File System (Definition, Advantages & Disadvantages)

Definition

A Flat File System is a simple database system that stores data in a plain text format,
where records are separated by delimiters (e.g., commas, tabs, or new lines). Each file
typically contains a single table with no structured relationships between records.

Example: CSV (Comma-Separated Values) files, text files (.txt).

Advantages of Flat File System

� Simplicity – Easy to create and use without requiring complex database software.
� Lightweight – Requires minimal system resources, making it suitable for small-scale
applications.
� Portability – Can be easily transferred between different systems without
compatibility issues.
� Fast Access for Small Data – Works efficiently for small datasets with simple
operations.
� No Need for Specialized Software – Can be accessed using basic text editors or
spreadsheet programs like Microsoft Excel.
Disadvantages of Flat File System

� Data Redundancy – Repeated storage of the same data leads to increased storage
usage.
� Lack of Relationships – No support for relational links between records, making data
management difficult.
� Limited Scalability – Not suitable for handling large amounts of data efficiently.
� Slow Search and Retrieval – Searching for specific data can be slow since there are
no indexing mechanisms.
� Data Integrity Issues – Ensuring data consistency is challenging due to the absence
of constraints like primary keys or foreign keys.

3. ER Diagrams

ER Diagrams (Entity-Relationship Diagrams)

Definition

An Entity-Relationship (ER) Diagram is a graphical representation of entities, their


attributes, and relationships within a database. It helps in designing and visualizing
database structures before implementation.

Components of ER Diagrams

a. Entity – Represents an object or thing in the system (e.g., Student, Employee).

o Types:

 Strong Entity – Exists independently (e.g., Student).

 Weak Entity – Depends on a strong entity (e.g., OrderItem


depends on Order).

o Notation: Represented by a rectangle.

b. Attribute – Represents the properties of an entity (e.g., Name, Age).

o Types:

 Simple Attribute – Cannot be broken down (e.g., Roll Number).


 Composite Attribute – Can be divided into sub-parts (e.g., Name
→ First Name, Last Name).

 Derived Attribute – Derived from other attributes (e.g., Age from


Date of Birth).

 Multivalued Attribute – Can have multiple values (e.g., Phone


Numbers).

o Notation: Represented by an ellipse.

c. Relationship – Shows the association between entities (e.g., A Student enrolls


in a Course).

o Types:

 One-to-One (1:1) – Each entity instance is related to one instance


of another entity.

 One-to-Many (1:M) – One entity instance is related to multiple


instances of another entity.

 Many-to-Many (M:N) – Multiple instances of one entity are related


to multiple instances of another.

o Notation: Represented by a diamond.

d. Cardinality – Defines the number of instances of one entity that can be


associated with instances of another.

o Common types: 1:1, 1:M, M:N.

Example ER Diagram

For a Student and Course relationship:

• Entities: Student (ID, Name, Age) & Course (CourseID, CourseName).

• Relationship: Enrolls (between Student and Course).

• Cardinality: Many-to-Many (M:N) since a student can enroll in multiple courses,


and a course can have multiple students.
Advantages of ER Diagrams

� Visual Representation – Makes database design easy to understand.


� Identifies Relationships Clearly – Helps define how data interacts.
� Efficient Database Structure – Reduces redundancy and improves efficiency.
� Easy to Convert into Tables – Can be directly translated into relational schema.

Disadvantages of ER Diagrams

� Complexity in Large Databases – Becomes difficult to manage for large


systems.
� Limited Representation – Cannot define procedural logic or constraints in
detail.
� Not Suitable for Unstructured Data – Best for structured relational databases
only.

4. Types of Keys in SQL

Types of Keys in SQL

Keys in SQL are used to identify and maintain relationships between records in a
database. They help enforce uniqueness, integrity, and consistency of data.

1. Primary Key �

• A unique identifier for each record in a table.

• Cannot contain NULL values and must be unique.

• A table can have only one primary key (which may consist of a single or multiple
columns).

Example:
2. Candidate Key �

• A set of attributes that can uniquely identify a record.

• A table can have multiple candidate keys, but only one can be chosen as the
primary key.

Example:

• In a Students table, both StudentID and Email can be candidate keys because
they uniquely identify a student.

3. Super Key �

• A super key is any set of attributes that can uniquely identify a record.

• It can contain additional unnecessary attributes beyond the minimum


required.

• Candidate keys are minimal super keys.

Example:

• {StudentID, Name} is a super key, but {StudentID} alone is a candidate key


because it is minimal.
4. Foreign Key �

• A foreign key is a column (or set of columns) that establishes a relationship


between two tables.

• It refers to the primary key in another table.

• Ensures referential integrity (i.e., prevents invalid data from being inserted).

Example:

(Here, StudentID in Enrollments refers to StudentID in Students.)

5. Unique Key �

• Ensures that all values in a column are unique.

• Unlike Primary Key, it can contain NULL values (but must still be unique).

Example:

6. Composite Key �

• A key formed by two or more columns together to uniquely identify a record.


• Used when a single column cannot uniquely identify a row.

Example:

(In this case, OrderID alone is not unique, but the combination of OrderID and
ProductID is.)

7. Alternate Key �

• A candidate key that is not chosen as the primary key.

• Acts as an alternative unique identifier for records.

Example:

• If EmployeeID is the primary key, then Email (which is also unique) is an


alternate key.

8. Surrogate Key �

• A system-generated unique identifier (often an auto-incremented ID).

• Used when no natural key is available.

• Usually an integer and does not carry business meaning.

Example:
(Here, CustomerID is a surrogate key generated automatically.)

Summary Table

5. DBA & Its Role

Who is a DBA?

A Database Administrator (DBA) is responsible for managing, securing, and optimizing


database systems to ensure efficient data storage, retrieval, and protection.

Key Responsibilities of a DBA:

a. Installation & Configuration – Sets up and configures database management


systems.

b. Database Design & Implementation – Creates schemas, tables, and


relationships for efficient data organization.

c. Data Security & Access Control – Manages user permissions and protects data
from unauthorized access.
d. Backup & Recovery – Ensures regular backups and disaster recovery planning.

e. Performance Tuning – Optimizes queries, indexing, and system performance.

f. Monitoring & Troubleshooting – Identifies and resolves database issues.

g. Data Integrity & Consistency – Ensures ACID compliance and prevents data
corruption.

h. Scalability & High Availability – Manages replication and clustering for large-
scale databases.

i. User Management – Controls database access and permissions.

j. Documentation & Reporting – Maintains database logs and performance


reports.

Types of DBAs:

• System DBA (manages DBMS software).

• Application DBA (optimizes databases for applications).

• Security DBA (focuses on data protection).

• Performance DBA (tunes databases for efficiency).

Conclusion

A DBA ensures databases are secure, optimized, and always available, playing a crucial
role in IT infrastructure.

6. Relational Algebra

Definition:

Relational Algebra is a mathematical query language used to retrieve and manipulate


data in relational databases. It provides a foundation for SQL and works with relations
(tables) using set-based operations.

Basic Operations:

a. Selection (σ) → Filters rows based on a condition.

o Example: σ Age > 18 (Students) → Select students older than 18.

b. Projection (π) → Selects specific columns (attributes).


o Example: π Name, Age (Students) → Get only names and ages.

c. Cartesian Product (×) → Combines all rows from two tables.

o Example: Students × Courses

d. Union (∪) → Combines two tables and removes duplicates.

o Example: Campus1_Students ∪ Campus2_Students

e. Intersection (∩) → Returns common rows between two tables.

o Example: CourseA_Students ∩ CourseB_Students

f. Set Difference (−) → Finds rows in one table but not in another.

o Example: CourseA_Students − CourseB_Students

g. Join (⋈) → Merges two tables based on a common attribute (foreign key).

o Example: Students ⋈ Students.StudentID = Enrollments.StudentID


Enrollments

Conclusion:

Relational Algebra forms the theoretical backbone of SQL queries and helps in
understanding data retrieval operations efficiently.

7. Normalization (Definition, Types)

Definition:

Normalization is the process of organizing data in a database to eliminate


redundancy, improve data integrity, and ensure efficient data storage. It involves
dividing large tables into smaller, related tables and applying normal forms (NF) to
remove anomalies in data insertion, deletion, and updating.

Types of Normalization

1. First Normal Form (1NF) – Eliminate Repeating Groups

• Each column should have atomic values (no multiple values in a single cell).

• Each row should have a unique identifier (primary key).


� Example (Before 1NF):

� After 1NF

2. Second Normal Form (2NF) – Remove Partial Dependency

• Achieves 1NF.

• Ensures that non-key attributes depend on the whole primary key, not just a
part of it.

� Example (Before 2NF):

� After 2NF (Splitting Tables):

1. Students Table:
| StudentID | StudentName |
|-----------|------------|
| 101 | John |
| 102 | Emma |

2. Courses Table:
| CourseID | CourseName |
|----------|------------|
| C001 | DBMS |
| C002 | OS |

3. Enrollment Table (Mapping Student to Courses):


| StudentID | CourseID |
|-----------|----------|
| 101 | C001 |
| 102 | C002 |

3. Third Normal Form (3NF) – Remove Transitive Dependency

• Achieves 2NF.

• Non-key attributes should not depend on another non-key attribute.

� Example (Before 3NF):

� After 3NF (Moving Department Data to a Separate Table):

1. Students Table:
| StudentID | Name | DepartmentID |
|-----------|-------|-------------|
| 101 | John | D001 |
| 102 | Emma | D002 |

2. Departments Table:
| DepartmentID | DepartmentName |
|-------------|-------------------|
| D001 | Computer Science |
| D002 | Mathematics |

4. Boyce-Codd Normal Form (BCNF) – Handle Multi-Candidate Keys

• Achieves 3NF and ensures that every determinant is a candidate key.

• Used when multiple candidate keys exist in a table.

� Example (Before BCNF):


� After BCNF (Splitting the Table to Remove Anomalies):

1. Professors Table:
| ProfessorID | CourseID |
|------------|----------|
| P101 | C001 |
| P102 | C002 |

2. Classroom Table:
| CourseID | Classroom |
|----------|-----------|
| C001 | Room 1 |
| C002 | Room 2 |

5. Fourth Normal Form (4NF) – Remove Multi-Valued Dependency

• Achieves BCNF and removes multi-valued dependencies (one attribute


should not determine multiple independent attributes).

� Example (Before 4NF – Multi-Valued Dependency):

� After 4NF (Splitting into Two Tables):

1. Employee-Skills Table:
| EmployeeID | Skill |
|-----------|--------|
| 201 | Python |
| 201 | Java |

2. Employee-Languages Table:
| EmployeeID | Language |
|-----------|---------|
| 201 | English |
| 201 | Hindi |

6. Fifth Normal Form (5NF) – Solve Join Dependency

• Ensures that every join dependency is a result of candidate keys.

� Example (Before 5NF – Redundant Join Dependencies):

� After 5NF (Breaking Join Dependencies):

1. Projects Table:
| ProjectID | EmployeeID |
|----------|------------|
| P01 | E101 |
| P01 | E102 |
| P02 | E101 |

2. Roles Table:
| EmployeeID | Role |
|-----------|---------|
| E101 | Developer |
| E102 | Tester |

Conclusion

Normalization is essential for reducing data redundancy, maintaining data


consistency, and improving database performance. The higher the normal form,
the more structured and optimized the database becomes.

8. Generalization

Definition:
Generalization is a bottom-up approach in database design where multiple specific
entities with common attributes are merged into a single generalized entity
(superclass).

Example:

• Car, Bike, and Truck → Generalized into Vehicle (Superclass).

• Common attributes (e.g., Model, VehicleID) are stored in Vehicle, while


unique attributes remain in subclasses.

Key Points:

� Reduces redundancy by storing shared data in one place.


� Simplifies database structure and increases reusability.
� Bottom-up approach, opposite of specialization (which divides entities).

Difference Between Generalization & Specialization:

Conclusion:

Generalization helps organize data efficiently, improving database management


and reducing duplication.

9. Specialization

Definition:

Specialization is a top-down approach in database design where a general entity is


divided into multiple specialized sub-entities based on specific attributes.

Example:

• Employee (General Entity) → Specialized into Manager (Manages team) and


Engineer (Develops software).
• Unique attributes are stored in subclasses, while common attributes remain
in the superclass (Employee).

Key Points:

� Increases specificity by breaking down entities.


� Reduces data redundancy and improves data organization.
� Top-down approach, opposite of generalization (which merges entities).

Conclusion:

Specialization helps in efficient data structuring by breaking down entities into


more specific categories, making the database more detailed and functional.

10. 3 Schema Architecture (Definition, Diagram)

The 3-Schema Architecture in Database Management Systems (DMS) is a framework for


organizing data at different levels of abstrac�on. It consists of:

1. Internal Schema (Physical Level) o Deals with the

storage of data in the database.

o Defines how data is stored (indexes, file structures, data compression).

2. Conceptual Schema (Logical Level) o Represents

the overall structure of the database.

o Defines tables, rela�onships, constraints, and security without concern for


physical storage.

3. External Schema (View Level) o Provides

customized views for different users.

o Ensures data security by restric�ng access to only necessary data.

This architecture separates concerns, improves data independence, and enhances security
& usability in databases.
Explana�on:

1. External Schema (View Level) → Different views for different users.

2. Conceptual Schema (Logical Level) → Defines database structure logically.

3. Internal Schema (Physical Level) → Manages physical data storage.

This architecture ensures data abstrac�on, security, and independence in DBMS.

11. Data Independence

Definition:

Data Independence refers to the ability to modify the schema at one level without
affecting the schema at the next higher level. It helps in maintaining flexibility and
reducing dependency between database structure and applications.

Types of Data Independence:

1. Logical Data Independence → Changes in the logical schema (e.g.,


adding/removing attributes, splitting tables) do not affect applications using
the database.
o � Example: Adding a new column to a table without modifying
existing queries.

2. Physical Data Independence → Changes in the physical storage (e.g., data


location, indexing, compression) do not affect the logical schema or
applications.

o � Example: Changing the file storage format without modifying table


structure or SQL queries.

Key Benefits:

� Enhances flexibility in database design.


� Reduces dependency between storage and application layers.
� Improves maintainability by allowing independent modifications.

Conclusion:

Data independence ensures separation between data storage, structure, and


application logic, making databases more scalable and adaptable to changes.

12. Aggregation

Definition:

Aggregation is an ER modeling concept that represents a relationship between a


relationship and an entity. It is used when a relationship itself needs to participate in
another relationship.

Example:

• Entities: Student, Course, and Instructor

• Relationships:

o A Student enrolls in a Course.

o An Instructor oversees the enrollment process.

� Aggregation Representation:
Instead of creating separate relationships, we treat "Enrollment" as an abstract entity
and form a new relationship with Instructor.

Key Points:
� Simplifies complex relationships in ER diagrams.
� Enhances database structure by reducing redundancy.
� Represents higher-level relationships efficiently.

Conclusion:

Aggregation is useful when a relationship itself needs to be associated with another


entity, making the database model more structured and understandable.

13. Integrity Constraints

Integrity Constraints in DBMS (Short Summary)

Definition:

Integrity constraints are rules applied to maintain the accuracy, consistency, and
reliability of data in a database.

Types of Integrity Constraints:

1. Domain Constraint → Ensures values in a column belong to a specific data type


or range.

o � Example: Age must be between 18 and 60.

2. Entity Integrity → Ensures every table has a primary key, and it cannot be NULL.

o � Example: A StudentID cannot be NULL in the Students table.

3. Referential Integrity → Ensures foreign key values must match primary key
values in the referenced table.

o � Example: A CourseID in the Enrollment table must exist in the


Courses table.

4. Key Constraint → Ensures that a primary key is unique for each row.

o � Example: No two students can have the same StudentID.

5. NOT NULL Constraint → Prevents a column from having NULL values.

o � Example: A username cannot be left empty in a Users table.

Conclusion:
Integrity constraints prevent invalid data entry, ensuring data consistency and
correctness in the database.

a. Referential Integrity

Definition:

Referential Integrity ensures that a foreign key in one table always refers to a valid
primary key in another table, preventing orphan records.

Example:

• Students Table:

• Enrollment Table:

Key Points:

� Prevents orphan records (i.e., records that reference non-existent data).


� Ensures data consistency between related tables.
� Enforced using foreign key constraints in SQL.

Conclusion:

Referential Integrity maintains logical relationships between tables, ensuring data


accuracy in relational databases.
b. Domain Integrity

Definition:

Domain Integrity ensures that the values in a column follow a specific data type, format,
or range, preventing invalid data entry.

Example:

• Employee Table:

Key Points:

� Ensures values match the expected data type (e.g., Age must be an integer).
� Restricts values to valid ranges (e.g., Age ≥ 18).
� Enforced using CHECK, NOT NULL, UNIQUE, and data types in SQL.

Conclusion:

Domain Integrity prevents invalid, inconsistent, or meaningless data, ensuring data


accuracy and reliability.

14. Data Integrity

Definition:

Data Integrity ensures the accuracy, consistency, and reliability of data stored in a
database. It prevents unauthorized changes, duplication, and data corruption.

Types of Data Integrity:

1. Domain Integrity → Ensures values in a column follow a specific data type,


format, or range.
o � Example: Age must be ≥ 18.

2. Entity Integrity → Ensures every table has a primary key, and it cannot be
NULL.

o � Example: A StudentID must be unique and non-null.

3. Referential Integrity → Ensures a foreign key always refers to a valid primary


key in another table.

o � Example: A CourseID in the Enrollment table must exist in the


Courses table.

4. User-Defined Integrity → Custom rules set by users to enforce business logic.

o � Example: A discount cannot be more than 50%.

Key Benefits:

� Prevents data corruption and inconsistency.


� Ensures data remains accurate and meaningful.
� Maintains relationships between tables in a structured way.

Conclusion:

Data Integrity is crucial for reliable databases, ensuring stored data remains valid,
accurate, and secure over time.

15. Instance

Definition:

An Instance in DBMS refers to the actual data stored in a database at a specific


moment. It represents a snapshot of the database at a given time.

Example:

Consider a Students Table:


• The structure of the table (columns) is called the Schema.

• The current rows (actual data) represent the Instance at that moment.

Key Points:

� Dynamic – Instances change as data is inserted, updated, or deleted.


� Different from Schema – Schema is fixed, but an Instance changes over time.
� Snapshot of Data – Represents the database’s current state.

Conclusion:

An Instance is the real-time data in a database, while the Schema defines the
structure.

16. Attributes

Definition:

An Attribute is a column in a database table that represents a property or


characteristic of an entity.

Example:

For a Student entity, the attributes can be:

• StudentID (Unique Identifier)

• Name (Student's Name)

• Age (Student's Age)

• Course (Enrolled Course)


Types of Attributes:

1. Simple Attribute → Cannot be divided further (e.g., Age, Roll Number).

2. Composite Attribute → Can be split into sub-parts (e.g., Name → First Name,
Last Name).

3. Derived Attribute → Derived from other attributes (e.g., Age from Date of
Birth).

4. Multi-Valued Attribute → Can have multiple values (e.g., Phone Numbers).

5. Key Attribute → Uniquely identifies an entity (e.g., StudentID as Primary Key).

Key Points:

� Defines properties of an entity in a database.


� Essential for structuring database tables.
� Different types help organize data efficiently.

Conclusion:

Attributes store specific details about an entity, making data structured and
meaningful.

17. Different Database Users

1. Database Administrator (DBA)

� Manages the database, ensures security, backup, and performance tuning.


� Example: Grants user permissions, monitors system health.

2. End Users

� Regular users who interact with the database via applications.


� Example: A student checking exam results online.

3. Application Programmers

� Develop software that interacts with the database.


� Example: A developer coding a banking app using SQL queries.

4. System Analysts
� Design database structure and decide how data is stored and accessed.
� Example: A business analyst defining data flow for an e-commerce app.

5. Database Designers

� Create the database schema (tables, relationships, constraints).


� Example: Designing a table for storing employee records.

6. Sophisticated Users

� Write complex SQL queries to analyze data directly.


� Example: A data scientist running analytics on sales data.

7. Naïve Users

� Use the database indirectly through a simple UI without writing queries.


� Example: A customer booking a ticket on a travel website.

Conclusion:

Different users interact with databases based on their roles and expertise, ensuring
smooth operation and accessibility.

18. Data Models

Definition:

A Data Model defines how data is organized, stored, and managed in a database. It
provides a structured framework for database design.

Types of Data Models:

1. Hierarchical Model �

o Data is organized in a tree structure (Parent-Child relationship).

o � Fast retrieval but less flexible.

o � Example: Organization Structure (CEO → Manager → Employee).

2. Network Model �

o Uses a graph structure (Many-to-Many relationships).

o � More flexible than Hierarchical Model.


o � Example: Airline reservation systems.

3. Relational Model � (Most Popular)

o Data stored in tables (relations) using rows & columns.

o � Easy to use with SQL.

o � Example: MySQL, PostgreSQL, Oracle DB.

4. Entity-Relationship (E-R) Model 🏗🏗

o Uses ER Diagrams to represent entities & relationships.

o � Best for database design & planning.

o � Example: University Database (Students, Courses, Professors).

5. Object-Oriented Model 🏛🏛

o Stores data as objects (like in OOP).

o � Good for complex applications like multimedia & CAD.

o � Example: Image Processing, IoT Applications.

Conclusion:

Data Models help in structuring databases, ensuring efficient data storage &
retrieval.

a. Hierarchical Data Model

Definition:

The Hierarchical Data Model organizes data in a tree-like structure, where each
record has one parent and multiple children (one-to-many relationship).

Example:

• University Database

o University (Parent)

 Departments (Child Nodes)

 Professors (Sub-Child Nodes)


� Example Representation:
� University
� Computer Science
├──�
│ ├── � Professor A
│ ├── � Professor B
� Mechanical
├──�
│ ├── � Professor X

Key Features:

� Follows Parent-Child relationship (One-to-Many).


� Fast retrieval for hierarchical data.
� Used in early databases like IBM's IMS.

Advantages:

✔ Efficient for hierarchical data (e.g., File Systems, Organization Structure).


✔ Faster access due to predefined paths.

Disadvantages:

� Lack of flexibility (No Many-to-Many relationships).


� Difficult to modify (Changes require restructuring the entire hierarchy).

Conclusion:

The Hierarchical Model is efficient for structured data but not suitable for complex
relationships.

b. Network Data Model

Definition:

The Network Data Model organizes data using a graph structure, allowing many-to-
many relationships through multiple parent-child links.

Example:

• University Database

o A Student can enroll in multiple Courses.

o A Course can have multiple Students.


� Example Representation:
� Student ⬅➡ � Course ⬅➡ � Professor

Key Features:

� Uses a graph-like structure (records are connected via links).


� More flexible than the hierarchical model.
� Uses pointers to establish relationships.

Advantages:

✔ Supports many-to-many relationships.


✔ More efficient for complex data structures (e.g., airline booking systems).

Disadvantages:

� Complex to design & manage.


� Requires pointers, making traversal difficult.

Conclusion:

The Network Model is more flexible than the Hierarchical Model, making it suitable
for complex relationships like banking and airline systems.

SQL TOPICS :
1. SQL Commands

Definition:

SQL commands are instructions used to interact with a database, such as creating,
modifying, retrieving, and deleting data.

Types of SQL Commands:

1⃣ DDL (Data Definition Language) – Defines database structure.

• CREATE → Creates tables/databases.

• ALTER → Modifies existing tables.

• DROP → Deletes tables/databases.

• TRUNCATE → Deletes all records but keeps structure.

2⃣ DML (Data Manipulation Language) – Modifies data.

• INSERT → Adds new records.

• UPDATE → Modifies existing records.

• DELETE → Removes specific records.

3⃣ DQL (Data Query Language) – Retrieves data.

• SELECT → Fetches data from tables.

4⃣ DCL (Data Control Language) – Controls user access.

• GRANT → Provides access to users.

• REVOKE → Removes access from users.

5⃣ TCL (Transaction Control Language) – Manages transactions.

• COMMIT → Saves changes permanently.

• ROLLBACK → Undoes changes before committing.

• SAVEPOINT → Creates checkpoints in transactions.

Conclusion:

SQL commands help in managing, modifying, and securing databases, making


them essential for database operations.
2. Clause

Definition:

A Clause in SQL is a part of a query that helps filter, sort, or limit data retrieval.
Clauses are used with SQL commands like SELECT, INSERT, UPDATE, and DELETE.

Common SQL Clauses:

a. WHERE → Filters records based on a condition.

b. ORDER BY → Sorts results in ascending (ASC) or descending (DESC) order.

c. GROUP BY → Groups records with the same values.

d. HAVING → Filters grouped records (used with GROUP BY).

e. LIMIT → Restricts the number of rows returned.

f. JOIN → Combines rows from multiple tables.


Conclusion:

SQL clauses help refine queries, making data retrieval efficient and meaningful.

3. Transaction

Definition:

A Transaction in DBMS is a sequence of database operations that are executed as a


single unit of work. It ensures that either all operations are completed successfully
or none of them take effect, maintaining data integrity.

� Example: Transferring ₹1000 from Account A to Account B:

1. Debit ₹1000 from Account A.

2. Credit ₹1000 to Account B.

3. Commit or Rollback the transaction.

If any step fails (e.g., system crash), the transaction is rolled back, preventing data
inconsistency.

-------------------------------------------------------------------------------------------

States of a Transaction

1 Active – Transaction is being executed.


2 Partially Committed – All operations are executed but not saved.
3 Committed – Changes are permanently saved.
4 Failed – A step failed, leading to a rollback.
5 Aborted – The transaction is rolled back, returning the database to its original
state.

ACID Properties of Transactions

ACID properties ensure reliable transactions:

a. Atomicity → "All or Nothing"

• Ensures that either all operations succeed or none.

• � Example: If money is deducted but not credited, the transaction is rolled


back.

b. Consistency → Maintains Data Integrity

• Database must remain in a valid state before & after the transaction.

• � Example: Total money in accounts should remain the same before & after
a transfer.

c. Isolation → Transactions work independently

• One transaction should not affect another until it is completed.

• � Example: Two people booking the last movie ticket should not both
succeed.

d. Durability → Changes are permanent

• Once committed, changes persist even after a system crash.

• � Example: After a successful transfer, money must remain credited.


SQL Example of a Transaction

Conclusion:

Transactions ensure data reliability, consistency, and integrity, making them


essential for database operations.

4. SQL Join

Definition:

A JOIN in SQL is used to combine rows from two or more tables based on a related
column (like a foreign key).

Types of SQL Joins:

1 INNER JOIN – Returns only matching records from both tables.

2 LEFT JOIN (LEFT OUTER JOIN) – Returns all records from the left table and
matching records from the right table.
3 RIGHT JOIN (RIGHT OUTER JOIN) – Returns all records from the right table and
matching records from the left table.

4 FULL JOIN (FULL OUTER JOIN) – Returns all records when there is a match in
either table.

5 CROSS JOIN – Returns the Cartesian product of both tables (all possible
combinations).

6 SELF JOIN – A table joins itself.


Conclusion:

Joins help retrieve meaningful data from multiple tables by establishing


relationships between them.

You might also like