Dbms
Dbms
A database is a systematic and organized collection of data that is stored electronically and
can be easily accessed, managed, updated, and retrieved using a computer system.
1. Data Abstraction
➤ Hides the complexity of data storage from users.
2. Data Independence
➤ Allows changes in data structure without affecting application programs.
5. Data Integrity
➤ Maintains accuracy and consistency of data using rules (like constraints).
7. Concurrency Control
➤ Allows multiple users to access data at the same time without conflicts.
9. Multi-user Environment
➤ Supports simultaneous access by many users.
Advantages of DBMS:
3. Data Security
Access control and user authentication prevent unauthorized access.
4. Data Sharing
Multiple users can access data simultaneously (concurrency control).
8. Enforces Standards
Promotes standardization of data formats and access methods.
Disadvantages of DBMS:
1. High Cost
Expensive software, hardware, and maintenance.
2. Complexity
Requires skilled personnel to design, implement, and manage.
3. Performance Overhead
Extra processing due to abstraction, especially for simple tasks.
7. Data Corruption
A bug or error in DBMS can potentially corrupt the entire database.
1. End Users
Casual Users: Use complex queries occasionally.
3. Application Programmers
Develop applications that access the database using languages like Java or SQL.
4. System Analysts
Analyze business needs and design system requirements.
5. Database Designers
Design the database structure (tables, schema, keys).
1. Hierarchical DBMS :
2. Network DBMS :
A Network DBMS organizes data using nodes and connections (sets), allowing each child to
have multiple parent records. It supports many-to-many relationships, making it more flexible
than the hierarchical model but also more complex to manage. Example: IDMS, Integrated
Data Store.
A Relational DBMS stores data in the form of tables (relations). Each table consists of rows
(tuples) and columns (attributes). Relationships between tables are maintained through
keys, and data is managed using Structured Query Language (SQL). It is the most widely
used DBMS model. Example: Oracle, MySQL, MS SQL Server, PostgreSQL.
An Object-Oriented DBMS stores data in the form of objects, just like in object-oriented
programming. It supports inheritance, encapsulation, and polymorphism, allowing complex
data to be handled efficiently. It is best suited for applications requiring object representation.
db4o, ObjectDB.
5. Document-Oriented DBMS :
Features of SQL
2. Standardized Language
– SQL is the standard language for relational databases, supported by most DBMSs like
Oracle, MySQL, SQL Server, etc.
3. Data Querying
– You can retrieve data from tables using SELECT queries with conditions, sorting, and
filtering.
4. Data Manipulation
– SQL allows inserting, updating, and deleting data using INSERT, UPDATE, and DELETE.
5. Data Definition
– SQL lets you define or modify database structures using CREATE, ALTER, and DROP.
6. Data Control
– SQL controls user access with GRANT and REVOKE commands.
7. Transaction Control
– Commands like COMMIT, ROLLBACK, and SAVEPOINT help manage changes to data
safely.
3. Vendor Dependency
– SQL syntax can differ between databases (e.g., MySQL, Oracle), reducing portability.
5. Performance Issues
– Large or poorly written queries can be slow and affect database performance.
6. Security Risks
– Improper use can lead to SQL injection attacks, causing data breaches.
A data model defines how data is connected, stored, and accessed in a database. It
provides a structured framework to describe the data, relationships, constraints, and
operations.
A schema in a database is the overall logical structure of the database. It defines how the
data is organized and how the relationships among them are maintained. It includes tables,
fields, relationships, views, indexes, and more.
An instance of a database refers to the data stored in the database at a particular moment in
time. It is the snapshot of the database.
✅ Example:
A teacher views: Student(Name, RollNo, Marks)
A student views: Student(Name, Marks)
✅ Example:
Table: Student(RollNo, Name, DeptID)
Table: Department(DeptID, DeptName)
✅
Helps in performance optimization.
Example:
Data stored as binary files.
Indexes used for fast access.
Data Independence in DBMS refers to the ability to change the database schema at one
level without affecting the schema at the next higher level. It is a key feature of DBMS that
ensures flexibility and minimizes the impact of changes.
Definition: Ability to change the logical schema (like table structure, relationships, or
constraints) without changing the external schema or application programs.
Definition: Ability to change the physical storage of data without affecting the logical schema.
DML (Data Manipulation Deals with data operations SELECT, INSERT, UPDATE,
Language) like insertion, deletion, DELETE
updating
A database interface provides a way for users and applications to interact with the database
system. Interfaces can be command-based, graphical, or application-programming-based.
Menu-Based Interface: Provides options through menus. Suitable for beginners or clerical
users. Example: ATM software.
Form-Based Interface: Users enter data into forms with fields. Easy to use for data entry
tasks.
Graphical User Interface (GUI): Uses graphical elements like icons, windows, buttons.
Example: Microsoft Access, phpMyAdmin.
Natural Language Interface: Users type commands in natural language (like English).
Limited use but growing with AI.
Command Line Interface (CLI): Requires commands to be typed manually. Suitable for
advanced users. Example: SQL prompt.
The ER Model is a high-level conceptual data model used in database design. It provides a
graphical way to represent data, relationships between data, and constraints.
Steps in ER Modelling
1. Identify Entities
Find objects of interest (real-world things).
Example: Student, Teacher, Course
2. Identify Attributes
Define properties of each entity.
Example: Student → Name, Roll_No, Age
3. Identify Relationships
5. Define Cardinality
One-to-One, One-to-Many, or Many-to-Many relationships.
6. Identify Keys
Choose a unique attribute (Primary Key) for each entity.
7. Apply Constraints
Apply participation constraints (total/partial), cardinality, and integrity rules.
ER Diagram Symbols
Entity Rectangle
Attribute Oval
Key Attribute Underlined Oval
Relationship Diamond
Multivalued Attr Double Oval
Derived Attr Dashed Oval
Connecting lines Straight lines
Benefits of ER Modelling
Easy to understand.
Acts as a blueprint for database creation
Helps avoid redundancy and inconsistency.
1. Entity
An entity is a real-world object or thing that can be identified uniquely and has a distinct
existence.
It can be physical (like a person or a car) or conceptual (like a course or a bank account).
Example:
A student, a book, a teacher, a car.
🔹 2. Entity Set
An entity set is a collection of similar types of entities.
All entities in an entity set share the same attributes.
Example:
All students in a university form a Student entity set.
All books in a library form a Book entity set.
Weak Entity Set – does not have a primary key and depends on another entity.
🔹 3. Attribute
Attributes are properties or characteristics of an entity.
Each entity has a set of attributes that describe it.
Example:
For a Student: Name, Roll_No, Age, Gender
Types of Attributes:
Type
🔹 4. Relationship
A relationship shows how two or more entities are associated with each other.
Represented using a diamond in ER diagrams.
Example:
A Student enrolls in a Course.
A Doctor treats a Patient.
Super Key:
* A super key is a set of one or more attributes (columns) that, taken together, can
uniquely identify a record (row) in a table.
* It's a broad concept, and a table can have many super keys.
* A super key might contain extra attributes that are not strictly necessary for uniqueness.
Example: Consider the STUDENT table
Candidate Key:
* A candidate key is a minimal super key. This means it's a set of attributes that uniquely
identifies each record, and if you remove any attribute from it, it will no longer uniquely
identify the records.
* A table can have one or more candidate keys.
* All candidate keys are super keys, but not all super keys are candidate keys.
Example: For the STUDENT table below, STUD_NO can be a candidate key,
as it uniquely identifies each record.
Primary Key:
* The primary key is one of the candidate keys that is chosen by the
database designer to uniquely identify each record in a table.
* It's the most important key for a table and serves as its main identifier.
* Characteristics of a Primary Key:
* Unique: Each value in the primary key column(s) must be unique.
* Non-null: It cannot contain null values.
* One per table: A table can have only one primary key.
* It is often used to establish relationships with other tables.
Example:
Alternate Key:
* An alternate key is any candidate key that is not chosen as the primary
key.
* These keys still have the ability to uniquely identify records but are not the
designated primary identifier for the table.
Example: In the STUDENT table, both STUD_NO and PHONE are candidate
keys. If STUD_NO is chosen as the primary key, then PHONE would be
considered an alternate key.
Foreign Key:
* A foreign key is a column or a set of columns in one table that refers to the
primary key (or sometimes a unique key) in another table.
* It establishes a link or relationship between two tables, ensuring referential
integrity (meaning that relationships between tables remain consistent).
* Foreign keys can contain duplicate values and can also contain null values
(unless specifically constrained otherwise).
Composite Key (or Compound Key):
* A composite key is a key that consists of two or more attributes that, when
combined, uniquely identify a record in a table.
* None of the individual attributes in a composite key can uniquely identify
the record on their own.
Example: In the STUDENT_COURSE table, {STUD_NO, COURSE_NO} can
form a composite key to uniquely identify each record.
Relational DBMS owes its foundation to the fact that the values of each table
are related to others. It has the capability to handle larger magnitudes of data
and simulate queries easily.
In the relational database model, constraints are rules that maintain the
integrity, accuracy, and consistency of data. They act as safeguards to prevent
invalid or nonsensical information from entering the database.
Key Constraints: These are about uniquely identifying records (rows) and
establishing relationships.
Primary Key:
Uniquely identifies each tuple in a table.
Cannot be NULL or duplicate.
Example: Roll_No in a STUDENT table.
Candidate Key:
Any attribute (or set of attributes) that can act as a primary key.
Super Key:
A set of one or more attributes that can uniquely identify tuples.
May contain extra attributes.
Entity Integrity Constraint: This is a specific rule for Primary Keys: no part of a
Primary Key can contain a null value. This guarantees that every row can be
uniquely identified.
Example: Roll_No in a STUDENT table.
Goals of Normalization
Eliminate data redundancy
Ensure data consistency
Make data updates efficient
Improve database organization
A functional dependency occurs when the value of one attribute (or a set of
attributes) uniquely determines the value of another attribute. This relationship
is denoted as:
X→Y
Here, X is the determinant, and Y is the dependent attribute. This means that
for each unique value of X, there is precisely one corresponding value of Y.
Example:
Consider a relation:
Student(RollNo, Name, Dept)
1. Trivial FD:
A → B is trivial if B is a subset of A.
Example: {RollNo, Name} → RollNo
2. Non-Trivial FD:
A → B is non-trivial if B is not a subset of A.
Example: RollNo → Name
4. Partial Dependency:
If B depends on part of a composite key, not the whole.
Example: RollNo → Name (when {RollNo, Subject} is the key)
Example:
Let’s assume:
Then:
Normal Forms are different stages of normalization, and each stage imposes
certain rules to improve the structure and performance of a database. Let's
break down the various normal forms step-by-step to understand the
conditions that need to be satisfied at each level:
After 1NF:
1.Student(RollNo, Name)
2. Student_Subject(RollNo, Subject)
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
Different Types of SQL JOINs
Here are the different types of the JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched
records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and the
matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in either the
left or right table.
REVOKE Command
Use: To remove previously granted permissions.
Example:
REVOKE INSERT ON Employees FROM user1;
➡ Removes user1's permission to insert data into the Employees table.