0% found this document useful (0 votes)
9 views

What is Database

A database is an organized electronic collection of data managed by a Database Management System (DBMS) that facilitates storage, retrieval, and updating of information. DBMS types include Relational, NoSQL, Hierarchical, and Network DBMS, each serving different data structures and needs. Information Systems, such as Transaction Processing Systems and Management Information Systems, utilize databases to support decision-making and operational efficiency in various organizational contexts.

Uploaded by

ejazahmedejaz49
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

What is Database

A database is an organized electronic collection of data managed by a Database Management System (DBMS) that facilitates storage, retrieval, and updating of information. DBMS types include Relational, NoSQL, Hierarchical, and Network DBMS, each serving different data structures and needs. Information Systems, such as Transaction Processing Systems and Management Information Systems, utilize databases to support decision-making and operational efficiency in various organizational contexts.

Uploaded by

ejazahmedejaz49
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

What is Database?

A database is an organized collection of data that is stored and accessed electronically. It is designed to
allow for easy storage, retrieval, management, and updating of data. Databases are typically managed by
a Database Management System (DBMS), which acts as an interface between the data and the users or
applications that need access to it.
Example

Imagine an online shopping platform like Amazon:

Database Storage: The platform has a huge amount of data, including information about products, customers, orders,
inventory, and reviews. All this information is stored in a database.

•Products Table: Stores information about each product, such as name, price, description, stock
availability, and product ID.
•Customers Table: Stores details like customer name, email, shipping address, and customer ID.
•Orders Table: Contains information about orders placed, such as order ID, customer ID, product
ID, and quantity.
onlineshoppping example:The database ensures that every interaction (searching, purchasing, reviewing) is handled
efficiently, with data being stored and retrieved in real-time. It also allows for easy management of large amounts of data
without manual tracking.

key points
Organized structure: Data is structured in tables (like spreadsheets) with rows and columns .

Efficient retrieval: You can search, update, and manipulate data quickly.

Data integrity: Databases maintain accuracy and consistency of the data even when multiple users
access it at the same time.

Database Management System (DBMS) A Database Management System (DBMS) is


software that allows users to create, manage, and interact with databases. It provides tools to store,
retrieve, update, and manage data efficiently. The DBMS acts as an interface between the database and
the users or applications, ensuring that data is consistently stored and accessed securely .
Key Functions of a DBMS
Data Storage, Retrieval, and Update: It allows users to store data in a structured way (usually in tables)
and retrieve or update the data whenever necessary.

Data Security: It controls access to the database, ensuring that only authorized users can interact with
the data.

Data Integrity: Ensures that the data remains accurate, consistent, and valid, even when multiple users
access it simultaneously.

Backup and Recovery: Regularly backs up the database and helps restore data in case of a system failure.
• Types of DBMS:
Relational DBMS (RDBMS): Data is stored in tables with relationships between them. E.g.,
MySQL, PostgreSQL, Oracle DB.

NoSQL DBMS: For unstructured or semi-structured data. E.g., MongoDB, Cassandra.

Hierarchical DBMS: Organizes data in a tree-like structure. E.g., IBM’s Information


Management System (IMS).
Network DBMS: Data is represented as records connected by links. E.g., Integrated Data Store
(IDS).
Real-World Example: Social Media Platform (e.g., Facebook) In a social media platform like
Facebook, a DBMS plays a critical role in managing massive amounts of user data:
• User Data: Facebook has millions of users, each with their profiles containing data like name, age,
friends list, posts, photos, and messages.
Concept of system
• The concept of a system refers to a set of interconnected components that work together to
achieve a common goal. In any system, the individual parts (or subsystems) interact and depend
on each other to perform specific tasks or functions, and the overall purpose of the system is
accomplished through these interactions.
• Key Characteristics of a System:
Components: A system consists of several components or parts, each having its specific role. For
example, in a car system, the engine, brakes, and transmission are individual components.
Interrelationships: These components are not independent; they are connected and interact to
achieve a shared objective. For example, in a business system, marketing, sales, and customer
support departments interact to serve customers.
Boundary: Every system has defined boundaries that separate it from its external environment. For
instance, in a computer system, hardware and software interact within defined boundaries.
Key Characteristics of a System:
Input and Output: Systems take inputs (e.g., resources, data, energy) from their environment,
process them, and produce outputs (e.g., information, services, products).
• Purpose or Goal: A system is goal-oriented, meaning it exists to fulfill specific objectives. For
instance, an educational system's goal is to provide learning and skill development.
Types of Systems:
• Open Systems: These systems interact with their environment by exchanging inputs and outputs.
For example, a business organization is an open system that interacts with customers, suppliers,
and regulatory bodies.
• Closed Systems: These systems have minimal or no interaction with the external environment. An
example would be a mechanical clock, which operates based on internal processes without any
need for input from the outside world.
Systems in Technology: Computer System
A computer system includes:
Hardware (physical components like CPU, memory, and storage).
Software (programs and operating system ).
User: The person interacting with the computer .
• Information System (IS)
An Information System (IS) is a structured system that collects, processes, stores, and distributes
information to support decision-making, coordination, and control in an organization. It is
essential for enhancing efficiency and enabling data-driven decisions.
Classification of Information Systems: Information Systems are typically classified based on their
functionality and the management level they support.
Transaction Processing System (TPS):
Purpose: Automates routine, day-to-day operations to record transactions.
What it does: Records routine transactions, like sales and purchases.
Description: Handles everyday, routine tasks.

Real-Life Example:
Point of Sale (POS) systems in retail stores. These systems manage inventory, process customer
purchases, and handle returns. For example, each sale at a grocery store updates inventory levels
and generates sales data.
Management Information System (MIS ):
Purpose: Provides summarized and structured information to aid middle management in planning,
controlling, and decision-making.
What it does: Compiles data for managers to help them track performance and make decision.

Description: Summarizes data to assist managers in decision-making.

real life example;Sales performance reports in a retail company. Managers can track weekly,
monthly, and yearly sales data to determine trends and make decisions about promotions,
stocking, and more.
Decision Support System (DSS): Purpose:
Assists in making non-routine decisions by analyzing large volumes of data and
generating insights.
• What it does: Analyzes data to help make complex decisions.
• Example:A dashboard showing a hospital CEO the average patient wait times and hospital
occupancy rates, helping them make high-level decisions on resource allocation.
Executive Information System (EIS):

Purpose: Provides senior


What it does: Provides Description: Provides
executives with easy
senior leaders with a top executives with key
access to critical
snapshot of critical performance indicators
information for strategic
metrics. and trends.
decision-making.

example dashboard showing a hospital CEO the average patient wait times and hospital
occupancy rates, helping them make high-level decisions on resource allocation.

• Office Automation System (OAS): Purpose:
Supports a range of office functions and activities, enhancing collaboration and productivity.
• What it does: Simplifies everyday office tasks and improves communication.
• Description: Enhances productivity and office work.
• An office automation system is the tool that enables data to move from one system to another
on its own without human intervention and inaccuracies. These tools help organizations collect,
manage, and analyze securely to accomplish everyday tasks and processes.
Example: Microsoft Office Suite or Google Workspace used for word processing, data analysis,
and communication. Employees can collaborate on documents, schedule meetings, and manage
tasks seamlessly.
• Knowledge Management System (KMS):
Purpose: Facilitates the sharing, organization, and retrieval of knowledge within an organization.
What it does: Stores and shares knowledge across the organization
• Example. An online FAQ system at a tech company where employees can find answers to
common IT problems without needing to ask the IT department directly.
Database System;
A Database System is a structured system designed to store, manage, and retrieve data
efficiently. It consists of several components that work together to organize data, control access,
and maintain data integrity.
Description: An organized collection of data.
• Components of a Database System: Database:
• Description: The organized collection of structured data.
• Example: A database could be a collection of customer records in an e-commerce store,
with details like names, addresses, and order history.
Database Engine: Description: The core service that processes database requests and
performs CRUD (Create, Read, Update, Delete) operations.
• Example:When a user searches for "smartphones" on an e-commerce site, the database
engine processes the request and retrieves product data, prices, and stock levels from
the database.
• Database Schema:
• Description: The structure or blueprint that defines how data is organized in tables and
relationships. The blueprint of the database that defines tables, fields, and relationships.

• Example:In a university database, the schema could define tables for Students, Courses, and
Enrollments with relationships between them.

Query Processor:
Description: Interprets and executes queries (usually written in SQL) submitted by users.
• Example:In a bank’s system, when a manager queries "all transactions above $10,000 in the last
month," the query processor interprets the SQL query, retrieves the relevant transactions, and
displays the results for analysis.
Data Dictionary:
Description: A catalog containing definitions, structures, and rules for the data in the database

Example:In a hospital’s system, the data dictionary might define the "Patient ID" field as a unique integer
and specify that "Admission Date" is a date field. It ensures consistent data entry and usage across the
system.
• Users: Description: People who interact with the database system, including administrators,
developers, and end-users.

Example:

• Admins: In a corporate HR system, database administrators manage user permissions and


monitor data security

• End-users: HR staff who enter employee information and generate reports.

• IT Staff: Maintain the database’s health and update it as necessary

Data:
Definition: Raw facts and figures without context, which by themselves may not have meaning.
Raw, unprocessed values or facts, often without context or meaning on their own
Eample:In an online store, data could be individual numbers like "3456" or words like "Apple
iPhone 12, $799, black." By themselves, these pieces don’t tell the whole story but are essential
for creating context.

• Information:
Definition: Processed data that provides meaning and context, turning it into something
understandable and useful.
Example:When the weather station analyzes the data and reports, "The temperature is 72°F with
65% humidity, predicting clear skies." Now, this is information because it’s organized and
provides meaning, helping people understand the weather forecast.

• Metadata: Definition: Data about data that provides details about other data, like its source,
format, or structure.Information about the data itself, describing its attributes, structure, and
characteristics.
Example:For the weather report, metadata might include the time each data point was collected,
the location (latitude and longitude), and the units (°F for temperature, % for humidity). This
metadata is essential for interpreting and managing the data correctly but isn’t part of the
forecast itself.

• File: A collection of data or information stored on a computer. It can be of various types, like
text files, executable files, images, or audio files.
Example:Think of a file as a document or spreadsheet you save on your computer. In a database,
files hold all the tables and data, like a big Excel file that stores information in an organized way.

Directory / Folder: A location in the file system where files and other folders (subdirectories) are
stored. Directories help organize files.
Example:Just like you create folders on your computer to organize different types of documents (e.g.,
"Work" or "School"), databases use folders to store and organize files. For instance, one folder might hold
data files, and another might hold backup files.
File Extension: The suffix at the end of a file name (e.g., .txt, .jpg, .exe) that indicates the file type and
format. Operating systems often use this to determine which program to use to open the file.
Example: Imagine you have a .pdf file for a report and a .jpg file for an image. In databases, specific
extensions like .db or .bak indicate what each file contains (data, logs, backups) so the database knows
how to use them.
Path: The address that specifies the exact location of a file or folder within the computer's directory
structure. A path can be absolute (full location from root) or relative (location relative to current
directory).
Example:Think of a path like a full address. If you have a document saved
atC:\Users\Documents\Report.docx, that’s its path. In databases, paths show where each file lives so the
database can find it, like a specific folder path to the database's storage file.

File Size: The amount of data within a file, typically measured in bytes, kilobytes (KB), megabytes (MB),
gigabytes (GB), etc.
File Name: The label used to identify a file in a directory. It often includes both a name and an extension
(e.g., report.docx).
File Compression: The process of reducing the file size to save storage space or to make it easier to
transfer. Compressed files often have extensions like .zip or .rar.
Backup File: A copy of a file created for the purpose of restoring data in case of corruption or loss.
Backup files may have extensions like .bak or be located in backup directories
File Permissions: Settings that determine who can read, write, or execute a file. These permissions are
key to securing files, especially in multi-user systems.
File in Database: A file in a database is essentially where data is stored on the computer’s disk. Each file
can contain tables, indexes, logs, or other components that make up the database.
Example: Imagine a school where each student’s academic records are stored in separate folders. One
folder might hold all the students' grades, another folder could hold attendance records, and another
might hold disciplinary records. Each of these folders is like a file in a database, where each file serves a
different purpose but is part of the whole system of student records.
File System in Database: The file system is the underlying structure that organizes these files on the
storage device, determining how data is saved, accessed, and managed on a disk. It’s what allows the
database to find and organize files effectively.
Library System: Think of a large library where books are organized by genre, author, and title in a specific
order. The file system in this library helps librarians locate books quickly and put new ones in the right
place. In a database, the file system works similarly, organizing data files, transaction logs, and indexes in
a structured way on the computer’s hard drive
Association between Fields
In a database, association between fields refers to the relationship or connection between two or more
fields (columns) in a table or across different tables. These associations help ensure data integrity and
enable the database to provide meaningful information by linking related data.
Example: Imagine a library database with two tables

Books TableFields: Book_ID, Title, Author_ID, Genre, Publisher_ID


Authors Table,
Fields: Author_ID, Author_Name, Country

The association between Author_ID in the Books table and Author_ID in the Authors table connects each
book to its author. This association allows the database to know which author wrote a particular book
Types of Field Associations

1.One-to-One: Each entry in a field is uniquely linked to a single entry in another field

• Example: Student_ID in a Students table associated with a Student_ID in a Student_Contact table.


Each student has one contact detail.

.Employee and Employee Parking Spot


.Imagine a company database with two tables
a.Employees Table:Fields: Employee_ID, Name, Department, Parking_Spot_ID
b.Parking_Spots Table:.Fields: Parking_Spot_ID, Spot_Number, Location
• In this example
1.Each employee in the Employees table has a unique parking spot, identified by the Parking_Spot_ID
2.Each entry in the Parking_Spots table corresponds to a specific parking spot assigned to one employee
only.
2.One-to-Many: A field in one table can relate to multiple entries in another table
Example: An Author_ID in the Authors table can associate with multiple books in the Books table,
indicating that one author can write many books
3.Many-to-Many: Entries in one field can associate with multiple entries in another field, typically through
a linking table.
Example: In a school database, students can be associated with multiple classes, and classes can have
multiple students. This relationship is often managed through an intermediate Student_Class table.
Why Association Matters: Associations between fields are fundamental in relational databases because
they allow data from different parts of the database to connect in a logical and meaningful way. This
organization supports complex queries, data integrity, and easier retrieval of related data, making it
possible to analyze and process information effectively.

Association between Files and its types


In databases, an association between files refers to the way different files are connected or relate to each
other within the system. These associations help organize and retrieve related data effectively, especially
when multiple files hold different parts of related information.
Types of Associations Between Files
1.Sequential Association: Files are organized in a specific, sequential order, typically by a key field.
Example: A payroll file for employees might store records in sequence by Employee_ID. When the system
processes payroll, it reads the file in sequential order to ensure each employee is handled in turn.
2.Direct or Random Association: Files are accessed directly using a unique key, allowing the system to
jump to a specific record without needing to read from the beginning.
Example: In a customer database, a direct association might allow accessing a customer’s file by entering
their Customer_ID, immediately bringing up their information
3.Linked Association:Files are linked in such a way that each file points to the next one in a logical
sequence. This is often used in scenarios requiring related data stored in different files.
Example: A hospital database might link a patient's main file with other files, like medical history or billing
records, to create a chain of information that’s easily followed.
Example: Employee and Department Database
Consider a company’s database with two files: Employees and Departments. The Employees file stores
the details of each employee, and the Departments file stores the information about the departments.
• Employees Table: Fields: Employee_ID, Name, Department_ID, Salary

• Departments Table: Fields: Department_ID, Department_Name, Location

4.Linked Association:In this scenario, each employee in the Employees table is linked to a
Department through the Department id. The Department_ID in the Employees table points to the
department that the employee belongs to in the Departments table.

∙ This creates a linked association between the two tables. Each employee is linked to a specific
department, but you can also track other details about that department by following the link
from the employee’s Department_ID to the Department_ID in the Departments table.

5.Hierarchical Association:Files are organized in a hierarchy, much like a family tree, where one
main file (the parent) branches out to related files (children
Example: An organizational database could have a main "Departments" file that links to sub-files
for each department’s employees, projects, and budgets. This hierarchy makes it easy to retrieve
all related files by starting at the top level.

• 6.Relational Association: Files are associated based on relationships between data fields, which
helps create flexible and complex queries across files.
Example: In a relational database for an e-commerce site, a Customers file can be linked to an
Orders file through a common Customer_ID field, allowing the system to retrieve all orders
associated with a particular customer

Why File Associations Are Important: Associations between files help in organizing data and
ensure efficient data retrieval. They enable databases to handle large sets of related data by
structuring them in a logical and accessible way, improving both performance and the user's
ability to extract meaningful information

1.Sequential File Organization


In sequential file organization, records are stored in a sequential order, typically based on a key field like
ID, Name, or Date. When accessing the data, you have to read the records in sequence until you find the
one you're looking for.
Example:Student Attendance Register:Imagine a school’s attendance register where each student’s
attendance is recorded in order of the date. Each day’s entry is appended at the end, and you can only
retrieve records in the same sequence. If you need to find out the attendance for a specific date, you
would have to scan through all records from the start until you reach that date.
Advantages
Simple to implement and maintian
Suitable for batch processing.
Disadvantages:
Searching specific records can be slow because you have to read through each record in sequence.
Insertions and deletions require reordering or restructuring.
2.Indexed File Organization; An index file is created for faster access. The index maps a key (like
Customer_ID, ISBN, or Product_Code) to the location of the record. This allows direct access to records
without scanning the entire file.
Example:Think of a library’s database where books are cataloged by their ISBN number. An index is
created where each ISBN number is mapped to the location of the book's record in the database. When
you search for a book by its ISBN, the system uses the index to quickly find the book’s record without
scanning all books.
Advantages
Faster search and retrieval of records.
Efficient for applications requiring frequent lookups.

Disadvantages:
Requires additional storage for the index.
Index maintenance can add complexity (e.g., updating the index after changes).

3.Hashed File Organization: : A hash function is used to calculate the address (or location) of a record
based on a key. This allows for direct access to a specific record without the need for sequential search or
an index.
Example:In a banking system, each customer has a unique Account_Number. A hash function is applied to
the Account_Number, which directly points to the location of the customer’s record in the database. This
way, when you need to access a customer's details, the system immediately calculates the record's
location and retrieves it.
Advantages :
Very fast data access based on unique keys
Simple to implement for direct lookups.

Disadvantages:
Inefficient for range queries (e.g., find all accounts with balances over $1,000).
Hash collisions can occur, requiring additional handling (e.g., chaining or open addressing

4.Direct File Organization: : Each record is stored at a specific location, which is directly calculated
based on a key. There’s no need for sequential scanning or indexes because the record location is
computed directly.
Example:Imagine a postal code directory where each postal code corresponds to a specific geographical
area. The directory is designed such that each postal code’s location on the page or in the database is
calculated directly based on the code itself (e.g., by applying a hash or direct address computation).
Advantages:
Extremely fast access to records
No need for extra indexing or sequential searching.

Disadvantages:
Requires careful management of record placement
Not suitable for all types of data (e.g., when records don’t have unique keys).
5.Clustered File Organization: : In clustered file organization, related records are stored together
physically on the disk, reducing the need for additional disk accesses when retrieving related data.
Example:In a supermarket inventory system, products and their suppliers are stored together in the
database. This way, when you search for a specific product, you can retrieve both the product and the
related supplier details in a single access. Products from the same supplier may be grouped together in
the same physical storage area to minimize disk access time.

Advantages:

Reduces disk I/O by storing related records close together.


Improves performance for queries involving related data.
Disadvantages:
More complex to manage and reorganize records.
Not efficient for queries where records are not related or for random access.
6.B+ Tree File Organization: A B+ tree is a self-balancing tree data structure used for storing indexes. It
allows for fast searching, insertion, and deletion of records. It is particularly efficient for range queries, as
it maintains sorted order.
Example:In an e-commerce store, products are stored in a database where records are indexed by
Product_ID. A B+ tree is used to index the product records, allowing for fast search, sorting, and filtering.
For example, if you want to display products in a specific price range, the B+ tree allows efficient retrieval
of records within that range.

Advantages

Efficient for both search and range queries.


Balanced structure ensures consistent performance.
Disadvantages:
Requires additional storage for the index.
More complex to implement and maintain.


Data Structure: A data structure in computer science is a specialized format for organizing, managing,
and storing data efficiently so it can be accessed and modified easily. The choice of data structure directly
affects the efficiency of algorithms in terms of time and space.
Data structures help solve computational problems by enabling operations such as
• Searching (e.g., finding an item in a list),
• Sorting (e.g., arranging items in order),
• Insertion (e.g., adding new data),
• Deletion (e.g., removing data).
Types of Data Structures
Data structures are broadly classified into:
1. Linear Data Structures: Data is arranged sequentially.
1. Examples: Arrays, Linked Lists, Stacks, Queues
2. Non-Linear Data Structures: Data is organized in a hierarchical or interconnected format.
1. Examples: Trees, Graphs
Why Are Data Structures Important?
Efficiency: They optimize data processing operations (search, sort, update).
Scalability: Suitable structures help handle large amounts of data effectively.
Real-World Applications: Everything from search engines and social media to games and mobile apps
relies on data structures
1.Location Methods: location methods refer to techniques or algorithms used to find or access data
stored in a data structure. These methods are vital for efficient data retrieval and are broadly categorized
based on the type of data structure and how data is organized.
2.Sequential Search: Concept: A basic method where each item in a data structure (like an array or list) is
checked one by one until the desired item is found or the search ends.
Efficiency: Works well for small, unsorted datasets but is slow for large datasets.
3.Direct Access: Concept: Data is accessed directly using an index or key without needing to search
through other elements.
• Efficiency: Very fast, as it retrieves data in O(1)O(1)O(1) time.
• Use Case: Arrays
• Real-Life Example: Finding a person's name in a phonebook using a known page number
4.Binary Search: Concept: Efficient search in a sorted dataset by repeatedly dividing the search range in
half.
• Efficiency: (login) time complexity.
• Steps Compare the target with the middle element.If the target is smaller, search the left half; if
larger, search the right half.Repeat until the target is found or the range is
• Real-Life Example: Searching for a word in a dictionary by flipping to the middle page and
narrowing the search range
5.Hashing: Concept: Uses a hash function to compute an index or address for storing/retrieving data in a
hash table.
• Efficiency: O(1) on average for insertions, deletions, and lookups
• Use Case: Hash tables and hash maps.
• Real-Life Example: Retrieving a student’s details using their roll number as a key.
6.Tree Traversal (Binary Search Trees): Concept: Search in hierarchical structures like trees.In a binary
search tree (BST):
Start from the root node.,Traverse left for smaller values and right for larger values.,Best-case efficiency:
O(log⁡n)
Real-Life Example: Searching for a specific contact in a phonebook app where names are stored in
alphabetical order.
Choosing the Right Location Method
The choice of a location method depends on:
Data Size: Larger datasets require more efficient methods like binary search or hashing.
Data Organization: Whether data is sorted, structured hierarchically, or random.
Access Frequency: For frequent searches, direct access or indexing is preferred.
Space-Time Tradeoff: Hashing offers speed but may consume more space.
Pointers
Pointers in programming are variables that store the memory address of another variable. They are
fundamental to understanding dynamic memory management, data structures like linked lists, and
efficient coding practices
Types of Pointers
1:Null pointner: A pointer that is assigned the value NULL (or nullptr in modern C++) and doesn’t point to
any memory location. Purpose: To signify that the pointer is not pointing to any valid memory location.
2.Void Pointer: : A pointer that can hold the address of any data type. However, it cannot be
dereferenced directly.Purpose: To create generic pointers that can store the address of any data type.
• int x = 10;
• float y = 5.5;
• void* ptr; // Void pointer
• ptr = &x; // Store address of an integer
• ptr = &y; // Store address of a float
3.Wild Pointer: : A pointer that has not been initialized and points to a random memory location.
• Risk: Dereferencing a wild pointer can cause undefined behavior or crashes.
• int* ptr; // Not initialized
• *ptr = 10; // Dangerous, as it points to an unknown memory location
Real-Life Analogy: Calling a random phone number without knowing who will answer.
4.Dangling Pointer: : A pointer that points to a memory location that has been deallocated or deleted.
• Risk: Dereferencing a dangling pointer can lead to undefined behavior.
• Real-Life Analogy: Referring to an address of a house that has been demolished.
5.Constant Pointer: : A pointer whose value or the data it points to cannot be changed.
Real-Life Analogy: A pen that can write only on a specific notebook and cannot write on any other
notebook

Inter record Data Structure


An Inter-Record Data Structure refers to how relationships and data dependencies between records (or
entities) are structured, stored, and managed in a database or data storage system. These relationships
determine how records interact with each other and allow for efficient querying, updating, and
navigation of data.
Types of Inter-Record Data Structures
1.Hierarchical Data Structure:Organizes records in a tree-like structure, where each record (except the
root) has one parent and can have multiple children.
Example:
A company's organizational structure:
1.The CEO is at the top (root).
2.Managers are children of the CEO.3Employees report to Managers.
Implementation: Uses pointers or references to link parent and child records. Easy to navigate when
relationships are well-defined.
Example:File systems where folders (directories) can contain subfolders and files.
• Inflexible for complex relationships (e.g., many-to-many).

3.Network Data Structure: Organizes records in a graph-like structure where a record can have multiple
parent and child relationships.
Example:
University system:
Students enroll in multiple courses.
A course has multiple students
Implementation: Uses pointers to create a network of records. Supports many-to-many relationships.
Example: Airline reservation systems, where flights, passengers, and schedules are interconnected.
• Complex to design and manage

4.Relational Data Structure: Stores records in tables with rows and columns, where relationships between
records are established using keys
Example: A database table for Customers and another for Orders, linked by CustomerID
Implementation: Uses foreign keys to define relationships between records in different tables. Flexible,
easy to query using SQL.
Example:E-commerce systems for tracking users and their orders.
• Performance can degrade with complex joins in large datasets.
Key Points:
• The choice of inter-record data structure depends on:Data complexity (e.g., hierarchical vs. many-
to-many
• Access patterns (e.g., frequent lookups vs. complex joins
• System requirements (e.g., speed, flexibility, scalability).
Data Model
A data model in a Database Management System (DBMS) is a conceptual framework that describes the
structure, organization, and relationships of data in a database. Data models are essential for designing
databases and organizing data in a way that is both efficient and flexible.
Types of data models
There are several types of data models in DBMS, each with its own structure and features. The most
common types are:
 Hierarchical Data Model
 Network Data Model
 Relational Data Model
 Object-Oriented Data Model
 Entity-Relationship (ER) Model
1.Hierarchical Data Model:The hierarchical data model organizes data in a tree-like structure. Each record
has a single parent (except the root), and each parent can have multiple children. This is similar to how
organizational structures or directory trees are structured.
 Example: Company Organizational Chart
 Top-level: CEO
 Second level: Managers (Sales Manager, HR Manager)
 Third level: Employees (Sales Executive, HR Assistant) In this model, if you want to access a Sales
Executive, you must traverse through the CEO → Sales Manager → Sales Executive path.
2. Network Data Model: The network data model is similar to the hierarchical model but allows more
complex relationships. It organizes data using a graph structure where records can have multiple parent
nodes, making it more flexible than the hierarchical model.
 Example: University Enrollment System
 Students can be enrolled in multiple Courses.
 Courses can have multiple Instructors.
 Instructors can teach multiple Courses.
3. Relational Data Model: The relational data model is the most popular and widely used model in
modern DBMS. Data is stored in tables (also called relations), and relationships between data are
established using keys (primary keys and foreign keys). Tables are linked by common attributes.
Example: Online Shopping System
 Consider an online shopping platform with the following tables:
 Customers (CustomerID, Name, Email)
 Orders (OrderID, CustomerID, Date)
 Products (ProductID, Name, Price)
 OrderDetails (OrderDetailID, OrderID, ProductID, Quantity)
In this model: A Customer can place multiple Orders (1-to-many relationship).
An Order can have multiple Products through the Order Details table (many-to-many
relationship).
The relationships are formed using the CustomerI D, Order ID, and Product ID as foreign keys
linking these tables.
4.Object-Oriented Data Model: In the object-oriented data model, data is represented as objects, similar
to how data is structured in object-oriented programming languages (e.g., Java, Python). This model is
suitable for complex applications where both data and behavior are encapsulated in the same entity.
Example: Banking System
 Consider a banking system where we have the following classes:
 Account (attributes: accountNumber, balance)
 Customer (attributes: name, address, customerID)
 Transaction (attributes: transactionID, amount, transaction Type)
 The Account class could have methods like deposit() and withdraw(), while the Transaction class
would include methods to process transactions. In this model, data is more integrated with the
operations that can be performed on it.
5.Entity-Relationship (ER) Model: The Entity-Relationship (ER) model uses entities, attributes, and
relationships to represent real-world data and their relationships. An entity is any object or thing in the
real world that is distinguishable from other objects, and a relationship represents an association
between entities.
 Example: Library Management System
 Entities:
 Books (BookID, Title, Author)
 Members (MemberID, Name, Email)
 Relationships:
 A Member can borrow Books (many-to-many relationship)
Data Model in DBMS
Definition
• A data model is a conceptual framework or blueprint that defines how data is organized, stored,
and manipulated in a database system. It acts as a bridge between real-world scenarios and
database systems, providing a way to visualize and represent data relationships, constraints, and
structures.
Key Components of a Data Model
1. Entities: Real-world objects or concepts, such as "Employee" or "Product," represented in the
database.
2. Attributes: Properties or characteristics of entities, like "Name," "Age," or "Salary."
3. Relationships: Connections between entities, like "Employee works in Department."
Classification of Data Models
Data models are classified into three main categories:
• Object-based Data Models
• Physical Data Models
• Record-based Data Models
1.Object-based Data Models: These models focus on entities, their attributes, and relationships.
Types:
a. Entity-Relationship Model (ER Model):
Represents data using entities, attributes, and relationships.
Example:1. In a university database, "Student" and "Course" are entities, and "Enrolls" is the relationship
between them.
2.: Think of a classroom where "Student" (entities) attend "Classes" (another entity) and have "Grades"
(attributes).
b. Object-oriented Data Model: Integrates object-oriented programming principles like classes and
inheritance.
Example: A "Car" object can inherit properties from a "Vehicle" class
Real-World Example of Class and Object
Class:
• Think of a class as a blueprint or template for creating objects. It defines the properties
(attributes) and behaviors (methods) that objects of that type will have.
Object:
• An object is a specific instance of a class, representing a real-world entity that follows the
structure defined by the class.
Example: Car as a Class
• Class: Car
A car is a general concept, so we define it as a class with attributes and behaviors.
• Attributes (Properties):
Brand
Model
Color
Year
• Behaviors (Methods):
Start()
Drive()
Stop()
• Objects of the Class Car
• Specific cars in real life are objects of the "Car" class. Each object has its unique values for the
attributes but shares the same structure and behavior.
• Object 1:
• Brand: Toyota
• Model: Corolla
• Color: White
• Year: 2020
• Object 2:
• Brand: Honda
• Model: Civic
• Color: Black
• Year: 2022
c. Semantic Data Model: Adds meaning to data by linking it to real-world contexts.
Example: Adding metadata to describe how "Customer Data" is used.

Entity-Relationship Diagram (ERD)


Definition: ERD is a visual representation of the Entity-Relationship Model. It uses symbols (like
rectangles, ovals, and diamonds) to graphically depict the entities, attributes, and relationships defined in
the ERM.
Purpose: To provide a diagrammatic view of the database structure for easy understanding and
communication.

ERD VS ERM
ERD
• ERD is a visual representation of the Entity-Relationship Model. It uses symbols (like rectangles,
ovals, and diamonds) to graphically depict the entities, attributes, and relationships defined in the
ERM.
• Purpose: To provide a diagrammatic view of the database structure for easy understanding and
communication.
• Key Components:
• Entities: Real-world objects (e.g., Student, Course).
• Attributes: Properties of entities (e.g., Student Name, Course Code).
• Relationships: Connections between entities (e.g., A student enrolls in a course).
Example:
In a university system:
• Entities: Student, Course
• Attributes: Student ID, Name; Course ID, Title
• Relationship: "Enrolled" connects Student and Course.
• ERM focuses on what data is required and how it is interrelated, without delving into
implementation specifics.
ERM
• ERM is a conceptual framework used to represent and describe the logical structure of a
database. It defines entities, attributes, and relationships in a way that captures the real-world
scenarios and rules of the data.
Purpose: To develop a high-level blueprint of the database structure before implementation
• Key Symbols:
• Rectangle: Represents an entity.
• Oval: Represents attributes.
• Diamond: Represents relationships.
• Lines: Connect entities to their attributes and relationships.
Example:
An ERD for the university system would depict:
• A rectangle for "Student" with connected ovals for "Student ID" and "Name."
• A rectangle for "Course" with ovals for "Course ID" and "Title."
• A diamond labeled "Enrolled" connecting the two entities.
Key Differences Between ERM and ERD

3.Physical Data Models


• These models describe how data is stored physically in the database.
• Key Features: Focuses on hardware-specific details, such as storage structures, indexing, and file
organization.
Example: A database stores student records using a hash table for quick retrieval.
• Real-life Example: Think of how files are organized in your cabinet for faster access—by labels or
colors.
• Computer Example: Data blocks, pointers, and disk locations.
4.Record-based Data Models:
• These models represent data as records, rows, or tables. They are closer to how relational
databases work.
Types
• Relational Data Model
• Network Data Model
• Hierarchical Data Model
a.Relational Data Model: Uses tables (relations) to represent data.
• Real-life Example: A class attendance register with rows as students and columns for details like
name, ID, and attendance.
Computer Example: SQL table with commands like CREATE TABLE Student (ID, Name, Age
b.Network Data Model: Represents data as a graph with nodes and edges, allowing many-to-many
relationships.
Real-life Example: An organizational chart where an employee can report to multiple managers
c.Hierarchical Data Model:: Represents data as a tree structure with parent-child relationships.
Real-life Example: A family tree where a parent has multiple children
Keys
keys are used to uniquely identify records and establish relationships between tables.
1.Primary Key
Definition: A primary key is a unique identifier for a record in a table. No two rows in a table can have the
same primary key value. It ensures data integrity and uniqueness.
Example: In a Student table, the StudentID column might be the primary key, as it uniquely identifies each
student.
Student table

2. Foreign Key
Definition: A foreign key is a field in one table that uniquely identifies a row of another table. It establishes
a link between the two tables.
Example: In an Order table, the CustomerID might be a foreign key that links to the Customer table's
primary key.
Order Table:

3. Candidate Key
Definition: A candidate key is a column (or a set of columns) that could serve as the primary key for a
table. A table can have more than one candidate key, but one will be chosen as the primary key.
Example: In the Employee table, both EmployeeID and Email could be candidate keys because both
columns can uniquely identify an employee.
Employee Table: Both EmployeeID and Email could be candidate keys, but one would be chosen as the
primary key.

4. Unique Key
Definition: A unique key ensures that all values in a column (or combination of columns) are distinct
across all rows in the table. Unlike the primary key, a unique key can allow null values.
Example: In the Employee table, the Email column might be a unique key to ensure no two employees
share the same email address.
Employee Table: Here, Email is a unique key, ensuring no duplicates exist.

5. Composite Key
Definition: A composite key is a combination of two or more columns that together uniquely identify a
record. No single column can uniquely identify the record on its own.
Example: In a CourseEnrollment table, a combination of StudentID and CourseID might be used as a
composite key, ensuring that each student can only enroll in a specific course once.
CourseEnrollment Table:
6. Superkey
Definition: A superkey is a set of one or more attributes that can uniquely identify a row in a table. A
superkey may contain unnecessary attributes that do not need to be part of the key.
Example: In a Student table, a set of attributes like (StudentID, Name) could be a superkey, but only
StudentID is necessary to uniquely identify a student
Student Table: Here, StudentID alone is sufficient, but the combination of StudentID and Name is also a
superkey.

7. Alternate Key
Definition: An alternate key is any candidate key that is not chosen as the primary key. These keys could
potentially serve as the primary key but are not selected.
Example: In the Employee table, if EmployeeID is the primary key, Email could be an alternate key.
Employee Table: Here, Email is an alternate key because it could also serve as the primary key.

8. Secondary Key
Definition: A secondary key is used for indexing and is not necessarily unique. It helps in searching for data
but does not serve as the primary identifier.
Example: In a Library system, a BookTitle could be a secondary key used to search for books, but the
BookID is the primary key.
Book Table: Here, BookTitle could be used as a secondary key for searching, but BookID is the primary
key.

9. Natural Key
Definition: A natural key is a key that is formed from the actual data in the real world. It is a naturally
occurring key, such as a Social Security Number or Email address.
Example: An Employee table might use a SocialSecurityNumber as a natural key.
Employee Table: Here, the SSN is a natural key because it's a real-world unique identifier.

Conclusion
Each type of key serves a specific purpose in ensuring data integrity, uniqueness, and efficient
relationships between tables in a relational database.
Database Design
Introduction to Database Design
• Database design is the process of defining the structure of a database, including how data is
stored, organized, and accessed. The goal is to create a database that is efficient, easy to manage,
and can handle the business needs it is intended for.
• A well-designed database ensures that data is stored in a way that minimizes redundancy,
maximizes efficiency, and supports the required queries and transactions.
Example:Think of a library management system. You need to design a database that holds data on books,
borrowers, and transactions. The design should be such that you can easily search for books, check
availability, and track borrowings and returns. A poorly designed database might result in lost

data,inconsistent records, and slower queries, which would negatively impact library operations .
Steps of Database Design
Database design typically follows these steps:
1. Requirement Analysis
2. Conceptual Design (ER Modeling)
3. Logical Design (Schema Definition)
4. Normalization
5. Physical Design
6. Implementation
7. Testing and Evaluation
8. Maintenance

1. Requirement Analysis
In this step, you gather all the requirements of the business or application to understand what kind of
data needs to be stored, what kinds of queries will be run, and how the data will be accessed.
Example:For a school management system, the requirement might be to track student information
(name, age, grades), teacher details (subjects, schedules), and class assignments (subject, date, etc.).
You'll need to know who will be accessing this data and for what purpose.
key
• Meet with stakeholders (managers, users) to gather information.
• Identify the types of data and how they will interact.

2. Conceptual Design (ER Modeling)


The next step involves creating a high-level data model that represents the data in a way that is
understandable and independent of the specific database system. This is typically done using an Entity-
Relationship (ER) model. Entities represent real-world objects (e.g., Student, Book, Order), and
relationships describe how they are linked.
Example :In the library system, you might create an ER diagram that has entities like Book, Author,
Member, and Transaction. The relationships could be that a Member borrows a Book, and a Transaction
tracks the borrow and return process.
key
• Create ER diagrams.
• Define entities, attributes, and relationships.
3. Logical Design (Schema Definition)
In this step, the high-level conceptual model is converted into a logical schema. The entities identified in
the ER model are translated into tables, and relationships are turned into foreign keys.
Example :After creating the ER diagram for the library system, you would define tables such as Books,
Members, Transactions, and Authors. Each table would have a primary key (e.g., Book_ID for the Books
table) and foreign keys (e.g., Member_ID in the Transactions table to link it with the Members table).
key
• Convert ER diagrams into relational tables.
• Define primary and foreign keys.
4. Normalization
Normalization is the process of organizing the database to eliminate redundancy and ensure data
integrity. This is done by breaking down tables into smaller, more focused tables and defining
relationships between them.
Example ;If in the Transactions table, you stored both Book_ID and Book_Title, this could cause
duplication of data (e.g., if the same book is borrowed multiple times). Instead, you'd normalize the
database to store the Book_ID in Transactions and keep the Book_Title in the Books table, ensuring that
the title is only stored once
key
• Apply normal forms (1NF, 2NF, 3NF) to ensure minimal redundancy.
• Split large tables into smaller ones.
5. Physical Design
This step involves deciding how the logical design will be implemented on the actual database system. It
focuses on storage details, indexing strategies, and how to optimize performance (such as defining which
fields should be indexed).
Example ;In the library system, you might decide to index the Book_ID and Member_ID to speed up
searches when looking up a book or member. You might also determine how to store data to ensure fast
retrieval, such as using clustered indexes.
• Define indexing strategies.
• Decide on file organization and storage methods.
6. Implementation
The database is created based on the design, including setting up tables, constraints, relationships, and
writing SQL queries for inserting, updating, and retrieving data.
Example In the library system, you would now create the database tables (e.g., CREATE TABLE Books (...);)
and implement the functionality for adding books, registering new members, and recording transactions
like borrowing and returning books
• Create tables and constraints using SQL.
• Write code to interact with the database.
7. Testing and Evaluation In
this step, you test the database to make sure it works correctly. You verify that all queries run efficiently
and that the data is accurate and consistent. You also test the system under different conditions to
ensure its scalability and robustness.
Example For the library system, you would test queries like searching for books, checking out books, and
adding new members. You might also simulate hundreds of people borrowing books at once to ensure
the system performs well under load.
• Write test cases to check for data consistency, performance, and correctness.
• Evaluate performance and make optimizations if necessary.
8. Maintenance Once
the database is live, it needs ongoing maintenance to ensure it stays in good health. This includes routine
backups, performance tuning, and updating the schema as business requirements evolve. Example In the
library system, you might periodically update the database to add new fields (e.g., a new column for
Publication_Year in the Books table) or clean up records of old transactions.
• Perform regular backups.
• Update schema and optimize queries based on usage patterns.
Real-Life Computer Example:
Let’s take an example of an E-commerce website. The database design process here could involve:
• Requirement Analysis: Identifying data needs such as product details, customer info, order
history, etc.
• ER Modeling: Creating entities like Customer, Order, Product, Payment, and defining relationships
between them.
• Logical Design: Translating ER diagram into tables like Customers, Orders, Products, etc.
• Normalization: Ensuring no redundant data (e.g., separating customer address into its own table).
• Physical Design: Deciding on indexing product names for quick search results.
• Implementation: Creating the database with tables and constraints.
• Testing: Testing product search, adding to cart, placing orders, and checking payment statuses.
• Maintenance: Updating product prices and running backups regularly.

Normalization in Database Design

Why do we need Normalization?


Normalization is the process of organizing data in a database to reduce redundancy (duplicate data) and
dependency. The main goals of normalization are:

1. Eliminate Redundant Data: Store data in such a way that no unnecessary duplicates exist.
2. Avoid Anomalies: Redundant data can lead to insertion, update, and deletion anomalies, which
can cause inconsistent and incorrect data.
3. Improve Data Integrity: By structuring data properly, we ensure that the database can maintain its
consistency

What is Normalization?
Normalization is a process that involves decomposing a large, complex table into smaller, simpler tables.
These tables are then related to each other using primary and foreign keys. The process of normalization
involves applying rules or normal forms to a database schema, each of which builds on the previous one.
Steps of Normalization:
1. First Normal Form (1NF)
2. Second Normal Form (2NF)
3. Third Normal Form (3NF)

1NF - First Normal Form


• A relation (table) is in First Normal Form (1NF) if it contains only atomic (indivisible) values. In
other words, each column must contain only one value per row, and each column must store
values of a single type.
Why we need 1NF: 1NF eliminates repeating groups and ensures that there is only a single value
per column for each record. This structure makes it easier to query and update the database.
Example Imagine a student course registration system. If you store multiple courses a student is enrolled
in within one column like this:

Split the table to ensure each column contains only atomic values:

2NF - Second Normal Form


• A relation is in Second Normal Form (2NF) if it is in 1NF and if all non-key attributes are fully
dependent on the primary key. This means that there should be no partial dependencies (i.e., no
non-key attributes depending on part of the primary key).
Why we need 2NF: 2NF ensures that every non-key column is dependent on the whole primary key, not
just part of it. This helps eliminate redundancy when composite keys (keys with multiple columns) are
used.
Example Consider a course enrollment system where we store the student’s name, course name, and
instructor:

We split the table into two tables:


3NF - Third Normal Form
• A relation is in Third Normal Form (3NF) if it is in 2NF and if all non-key attributes are not
transitively dependent on the primary key. This means that non-key attributes should not depend
on other non-key attributes.

Why we need 3NF: 3NF removes any transitive dependencies, which ensures that data is stored in the
most efficient way, without unnecessary relationships that could lead to anomalies

Example Imagine a student and course enrollment system where the instructor's office number is stored
with the course details:

To make this 3NF compliant:

We can split the table into two:

You might also like