What is Database
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
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.
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.
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):
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:
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
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
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
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:
Advantages
•
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(logn)
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
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.
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
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.
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)
Split the table to ensure each column contains only atomic values:
Example Imagine a student and course enrollment system where the instructor's office number is stored
with the course details: