Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views24 pages

Dbms

Uploaded by

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

Dbms

Uploaded by

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

Data is a collection of raw facts, figures, or symbols that have no meaning by themselves

until they are processed or organized.

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.

Key Characteristics of DBMS:

1. Data Abstraction
➤ Hides the complexity of data storage from users.

2. Data Independence
➤ Allows changes in data structure without affecting application programs.

3. Efficient Data Access


➤ Uses indexing, queries (like SQL), and optimization for fast data retrieval.

4. Data Security and Authorization


➤ Controls who can access what data using permissions and authentication.

5. Data Integrity
➤ Maintains accuracy and consistency of data using rules (like constraints).

6. Backup and Recovery


➤ Provides automatic tools to back up data and restore it in case of failure.

7. Concurrency Control
➤ Allows multiple users to access data at the same time without conflicts.

8. Reduced Data Redundancy


➤ Avoids storing the same data in multiple places, saving space and effort.

9. Multi-user Environment
➤ Supports simultaneous access by many users.

10. Data Consistency


➤ Ensures that all data remains accurate and up-to-date across the system.

Aspect​ ​ File System DBMS

Data Storage Data is stored in flat files Data is stored in structured


(like .txt, .csv).​ format in tables

Data Redundancy High – same data may be Reduced through


stored in multiple files. normalization and
relationships.
Data Access​ ​ Manual and complex using
programming languages. Easy with SQL queries.

Data Security Basic or no built-in security. Advanced security features


(user authentication, access
control).

Scalability Less scalable.​ Highly scalable for large


data and users.

Data Relationships​ Hard to manage Hard to manage


​ relationships between data. relationships between data

Data Integrity​ ​ Difficult to enforce. Maintains integrity through


constraints and rules.

Advantages of DBMS:

1. Data Redundancy Control


Avoids duplicate data by centralizing data storage.

2. Data Integrity and Accuracy


Ensures data is consistent and correct across the database.

3. Data Security
Access control and user authentication prevent unauthorized access.

4. Data Sharing
Multiple users can access data simultaneously (concurrency control).

5. Backup and Recovery


Automatic backup and restore mechanisms protect data from loss.

6. Improved Data Access


Easy querying using SQL enables quick and complex data retrieval.

7. Efficient Storage Management


Optimizes disk space and manages large volumes of data effectively.

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.

4. Size and Resource Requirement


Consumes more memory and processing power compared to file systems.

5. Risk of Central Failure


If the DBMS fails, the whole system may become inaccessible.

6. Upgradation and Migration Issues


Shifting to new systems or upgrading can be complex and risky.

7. Data Corruption
A bug or error in DBMS can potentially corrupt the entire database.

1. End Users
Casual Users: Use complex queries occasionally.

Naive Users: Use predefined forms and queries (e.g., clerks).

Sophisticated Users: Use DB tools for advanced queries (e.g., scientists).

Standalone Users: Use ready-made applications.

2. Database Administrator (DBA)


Manages the entire database system — handles security, backups, and performance.

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 :

A Hierarchical Database Management System stores data in a tree-like structure where


each record has a single parent and can have multiple children. This model is simple and
allows fast data access for structured and predictable queries, but it is rigid and hard to
modify. Example: IBM IMS.

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.

3. Relational DBMS (RDBMS) :

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.

4. Object-Oriented DBMS (OODBMS) :

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 :

A Document-Oriented DBMS (a type of NoSQL) stores data as documents, usually in


formats like JSON or XML. It is schema-less, meaning each document can have a different
structure. This model is highly flexible and scalable, ideal for unstructured or semi-structured
data. Example: MongoDB, CouchDB.

Structured Query Language (SQL) is a standard programming language specifically


designed for managing and manipulating relational databases. It is used to store, retrieve,
modify, and delete data in databases.

Features of SQL

1. Easy to Learn and Use


– SQL has simple and readable syntax, similar to English.

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.

8. Integration with Other Languages


– SQL can be embedded into programming languages (e.g., Java, C++, Python) for
application development.

9. Supports Functions and Clauses


– SQL includes features like aggregate functions (SUM, AVG) and clauses (WHERE,
GROUP BY, ORDER BY) for advanced querying.

Limitations of SQL (Briefly Explained)

1. Not Beginner Friendly


– Complex queries, especially with joins and subqueries, are hard for new learners.

2. Limited Procedural Capabilities


– SQL lacks features like loops, conditions, and functions found in programming languages.

3. Vendor Dependency
– SQL syntax can differ between databases (e.g., MySQL, Oracle), reducing portability.

4. Not Ideal for Unstructured Data


– SQL works best with structured/tabular data; not suited for multimedia or document files.

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.

Types of Data Models:

1. Hierarchical Data Model


Structure: Tree-like (parent-child relationship).
Each child has only one parent, but a parent can have multiple children.
Example: File system directories.
2. Network Data Model

Structure: Graph-like (many-to-many relationships).


Uses pointers to represent relationships.
Each record can have multiple parent and child records.

3. Relational Data Model

Structure: Data is organized into tables (relations).


Tables consist of rows (tuples) and columns (attributes).
Uses keys (primary, foreign) to establish relationships.
Example:
Student Table:
+----+--------+-----+
| ID | Name | Age |
+----+--------+-----+
| 1 | Ayesha | 20 |

4. Object-Oriented Data Model

Structure: Data is represented as objects, like in OOP languages.


Combines database capabilities with object programming.

5. Entity-Relationship (E-R) Model

Structure: Uses entities, attributes, and relationships.


Mostly used in database design (ER diagrams).
Example:
Entity: Student
Attributes: ID, Name, Age
Relationship: Enrolls in -> Course

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.

1. External Schema (View Level)

Also called: Subschema


Purpose: Describes how individual users or applications see the data.
Multiple external schemas can exist for different users.
Hides irrelevant data from the user.
Allows data security and privacy.

✅ Example:
A teacher views: Student(Name, RollNo, Marks)
A student views: Student(Name, Marks)

2. Conceptual Schema (Logical Level)

Describes the entire logical structure of the database.


Defines all entities, attributes, constraints, and relationships.
Hides physical details (like storage, indexes).
Only one conceptual schema per database.

✅ Example:
Table: Student(RollNo, Name, DeptID)
Table: Department(DeptID, DeptName)

3. Internal Schema (Physical Level)

Describes the physical storage of the database.


Includes details like:
Data files
Indexes
Data compression
Access methods (e.g., B-tree, hashing)


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.

Types of Data Independence:

1. Logical Data Independence

Definition: Ability to change the logical schema (like table structure, relationships, or
constraints) without changing the external schema or application programs.

2. Physical Data Independence

Definition: Ability to change the physical storage of data without affecting the logical schema.

Language Description Common Commands


DDL (Data Definition Defines the structure of the CREATE, ALTER, DROP,
Language)​ database (tables, schemas, TRUNCATE
etc.)

DML (Data Manipulation Deals with data operations SELECT, INSERT, UPDATE,
Language) like insertion, deletion, DELETE
updating​

DCL (Data Control Controls access to data in GRANT, REVOKE


Language) the database​

TCL (Transaction Control Manages database COMMIT, ROLLBACK,


Language)​ transactions to ensure SAVEPOINT
consistency​

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.

Application Programming Interface (API):​ Allows applications to communicate with the


database using programming languages. Example: JDBC (Java), ODBC (Open).

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

Define how entities are related.

Example: A Student enrolls in a Course.

4. Draw the ER Diagram


Use symbols like rectangles (entities), ovals (attributes), and diamonds (relationships).
Connect components appropriately.

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.

Diagram symbol: Rectangle


Example: Student

🔹 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.

Note: An entity set can be:

Strong Entity Set – has a primary key.

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​

Simple / Atomic: Cannot be divided​ Age, ID


Composite: Can be broken into sub-parts​ Name → First Name, Last Name
Derived: Can be calculated from other data​ Age (from DOB)
Multivalued: Can have multiple values​ Phone Numbers

Diagram symbol: Oval


Key attributes are underlined.

🔹 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.

Types of Relationship based on cardinality:

One-to-One (1:1) : Each entity is related to one of another e. g Person –


Passport
One-to-Many (1:N)​ One entity is related to many others​ E. g Teacher – Students
Many-to-Many (M:N)​ Many entities are related to many others e. g Student – Courses

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

STUD_NO SNAME ADDRESS PHONE

1 Hashim Habba Kadal 123456789

2 Zehran Natipora 223365796

3 Farzan Bemina 175468965


A super key could be a combination of STUD_NO and PHONE, as this combination uniquely
identifies a student.

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.

STUD_NO SS_NAME ADDRESS PHONE

1 HASHIM HABBA KADAL 123456789

2 Zehran NATIPORA 22 3365 796


3 FARZAN BEMINA 175468965

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:

STUDENT table -> Student(STUD_NO, SNAME, ADDRESS, PHONE) ,


STUD_NO is a primary key

Table same as above

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.

DDL (Data Definition Language)


DDL commands are used to define, modify, and delete the structure (schema)
of database objects. They deal with the blueprint of your database, not the
actual data residing within it. When you use DDL commands, you're changing
how the data is stored and organized.
Characteristics of DDL:
* Deals with Schema: Affects the database structure, tables, indexes, views,
etc.
* Auto-committed: Changes made by DDL commands are automatically and
permanently saved to the database. They cannot be rolled back.
* Used by DBAs/Designers: Primarily used during the database design and
setup phases by database administrators or developers.
Example:
CREATE TABLE Students (
ID INT,
Name VARCHAR(50)
);

DML (Data Manipulation Language)


DML commands are used to manage and manipulate the data stored within
the database objects. They deal with the content of your tables, allowing you
to insert, retrieve, modify, and delete individual records.
Characteristics of DML:
* Deals with Data: Affects the actual records (rows) within tables.
* Transactional: Changes made by DML commands are typically
transactional, meaning they can be rolled back if necessary (e.g., using
ROLLBACK or COMMIT commands).
* Used by Users/Applications: Frequently used by application developers and
end-users to interact with the data.
RDBMS stands for Relational Database Management Systems. It is a
program that allows us to create, delete, and update a relational database. A
Relational Database is a database system that stores and retrieves data in a
tabular format organized in the form of rows and columns. It is a smaller
subset of DBMS which was designed by E.F Codd in the 1970s. The major
DBMSs like SQL, My-SQL, and ORACLE are all based on the principles of
relational DBMS.

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.

Types of Relational Constraints:


* Domain Constraints: These define the allowed data types and value ranges
for each column (attribute). For example, an "Age" column might only accept
positive integers, or a "Gender" column might be limited to 'M' or 'F'. This
ensures data conforms to predefined types and formats.

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.

Referential Integrity Constraint: This maintains consistency between related


tables using Foreign Keys (FKs). A Foreign Key in one table references a
Primary Key (or Unique Key) in another table. It ensures that any value in the
foreign key column either exists as a valid primary key in the referenced table
or is null (if permitted). This prevents broken links between tables.

Normalization is a process in database design that organizes data to reduce


redundancy (duplicate data) and improve data integrity. It involves dividing
large tables into smaller, related tables and linking them using foreign keys.

Goals of Normalization
Eliminate data redundancy
Ensure data consistency
Make data updates efficient
Improve database organization

Why Normalization is Needed


To avoid anomalies:

Insertion anomaly – difficulty adding data due to missing other data.

Update anomaly – changing data in one place but not in others.

Deletion anomaly – deleting one piece of data unintentionally removes other


valuable data.

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)

If each RollNo is unique for every student, then:


RollNo → Name
RollNo → Dept
Means: Knowing the RollNo, we can determine the Name and Dept of a
student.

Types of Functional Dependencies:

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

3. Full Functional Dependency:


An attribute B is fully functionally dependent on A if it is dependent on the
entire A, and not just a part of it.
Example: {RollNo, Subject} → Marks

4. Partial Dependency:
If B depends on part of a composite key, not the whole.
Example: RollNo → Name (when {RollNo, Subject} is the key)

In a relation R, a transitive dependency exists when:


If
A → B and B → C,
then A → C is a transitive dependency,
provided A is not a superkey, and C is not a prime attribute (not part of any
candidate key).

Example:

Consider the relation:

Student(RollNo, Name, Dept, HOD)

Let’s assume:

RollNo → Dept (each student belongs to one department)


Dept → HOD (each department has one HOD)

Then:

👉 RollNo → HOD is a transitive dependency


(because RollNo → Dept and Dept → HOD)

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:

First Normal Form (1NF): Eliminating Duplicate Records


A table is in 1NF if it satisfies the following conditions:
All columns contain atomic values (i.e., indivisible values).
Each row is unique (i.e., no duplicate rows).
Each column has a unique name.
The order in which data is stored does not matter.

After 1NF:

RollNo Name ​ Subject

101​ Zara​ DBMS


101​ Zara​ OOP

Second Normal Form (2NF): Eliminating Partial Dependency


A relation is in 2NF if it satisfies the conditions of 1NF and additionally. No
partial dependency exists, meaning every non-prime attribute (non-key
attribute) must depend on the entire primary key, not just a part of it.

1.Student(RollNo, Name)

2. Student_Subject(RollNo, Subject)

Third Normal Form (3NF): Eliminating Transitive Dependency


A relation is in 3NF if it satisfies 2NF and additionally, there are no transitive
dependencies. In simpler terms, non-prime attributes should not depend on
other non-prime attributes.
Example (Before 3NF):

RollNo Name Dept HOD

101​ Zara​ CS​ Dr. Roy

Student(RollNo, Name, Dept)


Department(Dept, HOD)

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.

DCL (Data Control Language) includes commands such as GRANT and


REVOKE which mainly deal with the rights, permissions and other controls of
the database system. These commands are used to control access to data in
the database by granting or revoking permissions.
GRANT Command
Use: To allow users to perform certain actions like SELECT, INSERT,
UPDATE, DELETE, etc.
Example:
GRANT SELECT, INSERT ON Employees TO user1;
➡ Gives user1 permission to view and insert data into the Employees 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.

You might also like