LESSON 1 NOTES COMPUTER SCIENCE

 Database Management System                Chapter-1

1.    Data

Data is raw, unorganized facts or values. On its own, data does not have much meaning but it can be processed into useful information.

 Examples of Data:

  • Ramlal
  • security
  • Pokhara
  • 16

2.    Information

Information is what you get when data is processed, organized, or interpreted in a way that gives it meaning or context.

 Examples of Information:

  •  Ramlal is a 16-year-old security guard, living  in Pokhara.

3.     Database

A database is an organized collection of data that store and manage data so that it can be easily retrieved, updated, or analyzed by user.

      Examples of Databases:

  • A list of all worker in a factory.
  • All Facebook users’ data.
  • A mobile company’s user data.
  • Records of patients in a hospital.

4.     Data Processing

Data processing is the method of converting raw data into meaningful information using tools or software.

 Steps in Data Processing are as follow:

  1. Collect raw data (e.g., names, marks, locations).
  2. Organize it in a database (e.g., in a table).
  3. Process it using software (e.g., SQL, Excel, DBMS).
  4. Get meaningful information (e.g., average marks, top scorers, locations of users).

Data storage hierarchy or components of a file


·       Bit is smallest unit of memory. It can be either 0 or 1

·       Character is collection of 8 bits. It represents alphabet, number and anyone sign or symbol.

·       Field is a(data item/data element) which holds single facts or attribute to an entity(It is a attribute).

·       Record is a collection of related fields which represents a complete unit of information.

·      File is a collection of related records.

·      Database is a collection of integrated files.

Problems with File Processing System

Before databases, people used file processing systems to store data in individual files for each application. Each file was handled by a separate program. This created many problems:

 Common Problems are listed below:

1.     Data Duplication

o   Same data is stored in multiple files.
Example: A student's address stored in both the fee record file and the attendance file.

2.     Data Dependence

o   If you change the structure of one file, all programs using it must be changed too.
Example: If you add a middle name field in the student file, all related software must be updated.

3.     Lack of Data Integration

o   Data is spread across files and not connected.
Example: A teacher's schedule is in one file, and their subjects are in another, with no connection between them.


What is DBMS (Database Management System)?

DBMS is software used to create, store, manage, update, and retrieve data from a database.

Examples:

·       MySQL

·       Oracle

·       Microsoft Access

·       PostgreSQL


     Advantages of DBMS: (RISS CONTROL)

1.     Reduces Data Redundancy

o   Data is stored only once and shared.

2.     Controls Data Consistency

o   If a data value changes, it's updated everywhere automatically.

3.     Allows Data Sharing

o   Multiple users can use the same data at the same time.

4.     Ensures Data Security

o   Only authorized users can access or modify data.

5.     Maintains Data Integrity

o   Accepts only valid data (e.g., a student can't have negative marks).


     Disadvantages of DBMS:

1.     Expensive Hardware/Software

o   Requires computers with enough power and licensed software.

2.     Time-Consuming Setup

o   Setting up the system can take time and effort.

3.     High Operating Cost

o   Needs maintenance and power; can be costly for small users.

4.     Needs Skilled People

o   Trained database administrators are needed to manage it.

5.     Backup & Recovery Can Be Complex

o   If not managed properly, data recovery after failure can be difficult.


Function of DBMS

·      Provide data Independence

·      Concurrency control

·      Provides Utility services

·      Backup services

·      Provides security

·      Provides recovery services

·      Integrity

·      Multi-user sharing

Key Terms in File and Database Systems

1.    Table

A table is a fundamental structure used to organize and store data in a relational database. Table stores all of the records for a particular category. Each table in a database holds data about different but related subject.[it is a example of object in database]

2.    Field

            A field is an individual piece of data in a record. The fields can contain Name, Class, Roll no, Address, etc.

 

3.     Record

A record is a complete set of related data about one item in a file. A record is composed of fields and contain all the data about some person, item, etc. 

4.    File

A file is a collection of similar records.

 

 

5.    Object

A database object is any structure in a database that is used to store, manage, or interact with data. These are the building blocks of a database, and each object serves a different purpose.

·      Table: It is used to store information

·      View: It logically represent subset of data from one or more table

·      Sequence: It is use to generate primary key value

·      Index: It is used to improve the performance of queries

·      Synonym: It is use to give Alternate name to object

6.    Key

A key is an attribute or set of attribute which is used to uniquely identify a record of table.

1.    Primary key

·      A primary key is a special column or group of columns in a database table that is used to uniquely identify each record (row) in that table.

·      We can only have one primary key in a table.

·      Primary key doesn’t accept null value and each value should be unique in a row.

·      It is often used to connect one table to another in relational databases.

2.     Candidate key

·      A candidate key is any column or combination of columns in a table that can uniquely identify each row. 

·      These are the candidates for becoming the primary key.

·      Out of all candidate keys, one is chosen as the primary key.

·      Each record should be unique and must not be null.

3.     Alternate key

·      All the remaining candidate key which are not Primary key are Alternate key.

·      It uniquely identify each row in table.

·       Each record should be unique and must not be null.

4.     Foreign key

·      A foreign key is a key used to link two tables.

5.     Composite key

·      A composite key is a combination of two or more columns in a table that together uniquely identify a record. Columns may not be unique, but when combined, they create a unique identity for each row.


What is SQL[Structured Query Language]

SQL (Structured Query Language) is the standard language used to communicate with databases.

It is used to:

  • Store data
  • Retrieve data
  • Update data
  • Delete data
  • Manage database structures (like tables, users, etc.)

It works with relational databases like MySQL, Oracle, PostgreSQL, SQLite, etc.

The main Language provided by DBMS are:

1.    Data Defination Language (DDL)

2.    Data Manipulation Language (DML)

3.    Data Control Language (DCL)

1. Data Definition Language (DDL)

Used to define or change the structure of database objects like tables, schemas, etc.

Common DDL Commands:

  • CREATE: to create a new table or database
  • ALTER: to modify an existing table
  • DROP: to delete a table or database
  • RENAME: to rename database objects
  • TRUNCATE: to delete all data from a table quickly

Example:

CREATE TABLE Students (

  ID INT,

  Name VARCHAR(50)

);

 

2. Data Manipulation Language (DML)

Used to insert, update, delete, or retrieve data from the database.

Common DML Commands:

  • SELECT: to read data
  • INSERT: to add new data
  • UPDATE: to modify existing data
  • DELETE: to remove data

Example:

SELECT * FROM Students;

3. Data Control Language (DCL)

Used to control access to data in the database (i.e., permissions).

Common DCL Commands:

  • GRANT: to give user access
  • REVOKE: to remove user access

Example:

GRANT SELECT ON Students TO user123;

 

Database Models

There are mostly four types of database models which are:

1.    Hierarchical Database model

2.    Network Database model

3.    Relational Database model

4.    Object oriented Database model

1. Hierarchical Database model

·      A hierarchical database model is a data model in which the data are organized into a tree-like structure

·       Data are stored as records which are connected to one another through links.

·       Each node is related to others in parent-child relationship.

·       conventional database model.




2. Network Model


Features of Network Model:

1.    It is a modified model of hierarchical model

2.     In this model, each node may have several parents

3.     higher level of flexibility than hierarchical

4.     It Easier to restructure

5.     It can becomes complicated according to the increment in network

6.     It less user friendly than hierarchical network model.

Advantages of Network Model

1.    Supports many-to-many relationships.

2.    Provides faster data access through direct links (pointers).

3.    Ensures data integrity due to well-defined relationships.

4.    Offers better data independence than file-based systems.

5.    More flexible than hierarchical model.

3.  Relational Database Model (RDBMS)

  • The Relational Database Model organizes data into tables (also called relations).
  • Introduced by E.F. Codd in 1970.
  • It is the most widely used database model today (used in MySQL, Oracle, PostgreSQL, etc.).


Key Features of Relational Model

  • Data is stored in two-dimensional tables (rows and columns).
  • Tables are easy to understand and design.
  • Each table stores data about one type of thing (like students, courses, etc.).
  • Data from different tables can be connected using keys.

[Note: RDMS store data in tables(Field and Record)]

 

Keys in Relational Model

1. Primary Key (PK)

  • A unique identifier for each record in a table.
  • No duplicates allowed.
  • Cannot be null (must always have a value).
  • Example: StudentID in the Students table is a primary key. Each student must have a unique ID.

 2. Foreign Key (FK)

  • A field in one table that refers to the primary key of another table.
  • Used to link two tables and create relationships.
  • Example: DeptID in the Students table refers to the DeptID in the Department table.
  • DeptID in Student Table refers to the department of the student.
  • This creates a relationship between the two tables.

Advantages of Relational Model

  • Simple and logical structure.
  • Easy to update, search, and manage.
  • Tables can be linked using keys.
  • Data redundancy is reduced.
  • Supports complex queries and data relationships.

Disadvantages of Relational Model

·      It is expensive than other model.

·      It is more complex than other model.

·      It is confusing model because it applies too rules.

·      Only expert can use this model



 

 

4. Object oriented database model

·       An object-oriented database is a database that subscribes to a model with information represented by objects.

·       Object is any real things that are available in the world which has own data and method so, is independent.

·       Therefore objects contain both executable code and data.

·       There are other characteristics of objects such as whether methods or data can be accessed from outside the object.





 

 

Centralized database VS Distributed database Centralized database

 

 


What is it?

  • All the data is stored in one central computer (server).
  • Users (clients) connect to this server to store or get data.
  • Works like a client-server model.

 

Main Features:

  • Data is stored in one place only (central location).
  • Server can support one or many users.
  • Users connect to the server using a network.

Advantages:

  • Easy to maintain (because everything is in one location).
  • Simple data management.
  • Blocks unauthorized users (secure for small systems).
  • No risk of data mismatch across multiple places.
  • Good for small businesses or schools with limited data.

 

Limitations/Disadvantages:

  • If the server fails, all users lose access.
  • Not suitable for large companies with a lot of data or users.
  • All users depend on one single location.

 

Distributed Database


What is it?

  • A Distributed Database stores data across multiple computers.
  • These computers can be in the same building or in different parts of the world.
  • All computers are connected through a network.

 

Where is the data stored?

  • On internet servers, cloud systems, or company networks.
  • Admins can decide which location stores which part of the data.

Advantages:

  • Faster access to data for users in different places.
  • Data backup is easier since it's stored in multiple places.
  • Continues to work even if one server fails.
  • Local servers can handle local data requests, reducing load.

Disadvantages:

  • More complex to manage than centralized systems.
  • Needs good synchronization between all locations.
  • Harder to troubleshoot if something goes wrong.

Examples of Distributed Databases:

  • Google stores its search data in data centers across the world.
  • Amazon and Netflix use cloud-based distributed databases to serve millions of users.

Differences between centralized and distributed database system.

Centralized

Distributed

Simple type

Complex type

Located on particular location

Many geographical location

Only one server

Multiple server in many location

Suitable for small scale industries

Suitable for large scale industries

Maintenance is easy

Maintenance is difficult

Security is high

Security is low

Low speed

High Speed

Cheap

Expensive

Failure of server affect whole network

Doesn’t affect whole network

High chance of data loss

Less chance of data loss

Data Security

Data security means protecting data from unauthorized access, loss, or damage.
It ensures that only authorized people can view or use the data.

In databases and information systems, data security is very important to keep personal, business, or government data safe and private.

Goals of Data Security

  1. Confidentiality – Only the right people can access the data.
  2. Integrity – Data should stay correct and unchanged unless properly updated.
  3. Availability – Data must be available when needed, to authorized users.

Data Security Measures

1. Authentication

  • Verifies the identity of the user (e.g., username & password, fingerprint, OTP).
  • Example: Logging into your Gmail account with a password and 2-step verification.


2. Authorization

  • Allows only certain users to access specific data or actions.
  • Example: In a school database, only teachers can update marks; students can only view them.


3. Encryption

  • Converts data into unreadable code unless you have the correct key to decrypt it.
  • Example: WhatsApp messages are encrypted end-to-end.


4. Backup and Recovery

  • Keeping copies of data in safe storage in case of data loss or system failure.
  • Example: Backing up data to Google Drive or an external hard drive.


5. Firewall and Antivirus

  • Firewalls block unauthorized access from outside.
  • Antivirus protects against malware and harmful programs.
  • Example: Windows Defender, McAfee, etc.


6. Access Control

  • Limits who can read, write, or delete data.
  • Example: Admin can change all records, but users can only view.


7. Audit Trails

  • Keeps a log of who accessed or changed the data and when.
  • Helps in tracking suspicious activity.


8. Physical Security

  • Protects the servers and computers physically (using CCTV, locks, security guards).
  • Example: Server rooms in companies with restricted access.

Database Administrator (DBA)

·       Installs and configures database software.

·       Designs and creates database structures (tables, relations).

·       Manages users and sets permissions.

·       Ensures database security and prevents unauthorized access.

·       Performs regular data backups and recovery.

·       Monitors and improves database performance.

·       Maintains data integrity and consistency.

·       Fixes errors and resolves technical issues.

·       Updates and patches database systems.

·       Documents all database changes and settings.

 

 

 

 

 

 E-R Diagram

  It is a graphical representation of database. E-R Diagram is a graphical representation of different entities and their relationship.

  E-R model is based on the perception of a real world that consists of a collection of basic objects (entities) and relationship among these objects.

  The overall logical structure of a database can be express graphically by  

o   Rectangle: It represents of entity. It contains objects used in relational database.

o   Oval or Ellipse: it represents attributes (properties) of entities.

o   Diamond: It represents relationship among entities.

o   Line: It is used to link attributes to entity sets and entity set to relationship and vice-versa.

An E-R diagram for the relation writer writes book



E-R diagram shows the relationship between car purchaser and dealer 




 



 

Normalization (imp)

Definition

·       Normalization is the process of organizing a database to remove unnecessary data repetition.

·       It makes the database clean, simple, and efficient.

Why Do We Normalize?

To avoid:

·       Duplication of data

·       Insert Anomaly – Can't insert one thing without the other

·       Delete Anomaly – Deleting one data removes useful info

·       Update Anomaly – Must update in many places


Benefits of Normalization

·       Removes repetition

·       Saves space

·       Makes data easier to manage

·       Faster search and performance

·       Keeps your database clean and organized

Types of Normal Forms

1NF (First Normal Form)

Rules:

·       No repeating columns

·       Each column must have atomic (single) values

·       Each record must be unique

Unnormalized Table:

Name

Class

Subject 1

Marks 1

Subject 2

Marks 2

Ram Yadav

11

Computer

95

Account

78

Aashik Gautam

12

Computer

90

Account

82

Geeta Magar

11

Computer

89

Account

75

1NF Table:

Name

Class

Subject

Marks

Ram Yadav

11

Computer

95

Ram Yadav

11

Account

78

Aashik Gautam

12

Computer

90

Aashik Gautam

12

Account

82

Geeta Magar

11

Computer

89

Geeta Magar

11

Account

75

2NF (Second Normal Form)

Rules:

·       Must be in 1NF

·       No partial dependency (every column should fully depend on the full primary key)

Here, if (Name + Subject) is the primary key, we separate repeating data into new tables.

2NF Structure:

Student Table (Details):

SID

Name

Class

1

Ram Yadav

11

2

Aashik Gautam

12

3

Geeta Magar

11

Subject Table:

SubjectID

Subject

101

Computer

102

Account

Marks Table:

SID

SubjectID

Marks

1

101

95

1

102

78

2

101

90

2

102

82

3

101

89

3

102

75

3NF (Third Normal Form)

Rules:

·       Must be in 2NF

·       No transitive dependency
(non-key should depend only on primary key, not on other non-key)


3NF Example (Expanded):

SID–Student Table:

SID

Name

Class

1

Ram Yadav

11

2

Aashik Gautam

12

3

Geeta Magar

11

Subject Table:

SubjectID

Subject

101

Computer

102

Account

Marks Table:

SID

SubjectID

Marks

1

101

95

1

102

78

2

101

90

2

102

82

3

101

89

3

102

75

Remembering tips:

·       1NF: Break multivalued cells into rows

·       2NF: Remove partial dependence — break into smaller tables

·       3NF: Remove indirect (transitive) dependency — only keys should decide non-keys




Some important questions:
Q1.What is DBMS? Mention any two goals it aims to achieve.

Q2. Define a relational model. Why is it often preferred? List two advantages.

Q3. How is DBMS different from RDBMS? Give one example of each.

Q4. Compare a centralized and a distributed database system. Use a simple sketch or example.

Q5. What is a hierarchical model? Write any one benefit and one drawback.

Q6. Define normalization. Why is it used in databases? Mention any two common anomalies it removes.

Q7. Who is a DBA? State any two responsibilities and one quality a DBA should have.

Q8. Distinguish between a database and a DBMS with a real-life example.ss