Database Management System

    Database Management System

    Reading Mode:

    Unit:1

    Class 12 ┬╖Database Management System ┬╖ NEB Exam Preparation Guide

    How to use this guide: Learn the definitions first, then study the tables and examples. Normalization and SQL are the most practical parts, so practice writing them by hand. Practice questions are at the end.


    Table of Contents

    1. Basic Concepts: Data, Information, Data Processing
    2. File-Based System vs Database System
    3. Database and DBMS
    4. Database Terminology and Objects
    5. Keys
    6. Database Models
    7. Entity-Relationship (E-R) Diagram
    8. Normalization
    9. Centralized vs Distributed Database
    10. Data Dictionary, Integrity and Security
    11. Database Administrator (DBA)
    12. SQL
    13. Quick Revision Table
    14. Practice Questions

    1. Basic Concepts: Data, Information, Data Processing

    Data

    Data means raw facts and figures (numbers, text, images, sounds) that have no clear meaning on their own.

    Example: 101, Hari, Bharatpur

    TypeMeaningExamples
    Primary dataCollected first-hand for a specific purposeSurveys, questionnaires, observations
    Secondary dataAlready collected by someone elseCensus reports, sales reports, financial statements

    Data processing

    Data processing is the series of steps that convert raw data into meaningful output (information): input тЖТ processing тЖТ output.

    Information

    Information is processed data that has meaning and is useful for decisions. It answers questions such as who, what, where, and when.

    Example: "Hari lives in Bharatpur-11, Chitwan."

    Difference between data and information

    BasisDataInformation
    NatureRaw, unorganized factsProcessed, meaningful facts
    MeaningMay have no clear meaningAlways has meaning
    UseInput to a systemOutput of a system
    FormatNo fixed formatPresented as tables, charts, reports
    DependenceIndependentDepends on data
    Example101, Hari, 85"Hari (Roll 101) scored 85 marks"

    2. File-Based System vs Database System

    File-based (flat-file) system

    Records are stored in separate files, either on paper or in computer files, and each application manages its own files.

    Limitations of the file-based system

    1. Data redundancy: the same data is stored in many files
    2. Data inconsistency: copies of the same data may not match
    3. Program-data dependence: changing a file structure requires changing the program
    4. Poor data control: no central control over data
    5. Limited data sharing: each department keeps its own files
    6. Security problems: weak protection of data
    7. Incompatible file formats: files from different programs cannot be easily combined
    8. Fixed queries: only pre-written reports are possible

    Comparison

    BasisFile-based systemDatabase system
    Data storageSeparate files for each applicationCentral, integrated database
    RedundancyHighLow (controlled)
    ConsistencyOften inconsistentConsistent
    Data sharingDifficultEasy among many users
    SecurityWeakStrong (user rights, passwords)
    Backup and recoveryLittle or no supportBuilt-in support
    SearchingSlow, needs effortFast and easy
    MaintenanceDifficultEasier
    Data independenceNoYes

    3. Database and DBMS

    Database

    A database is an organized collection of related data stored so that it can be easily accessed, managed, and updated.

    Database system

    A database system is the combination of the database, the DBMS software, the application programs, and the users that work together to store and manage data.

    DBMS

    A Database Management System (DBMS) is software that lets users create, store, retrieve, update, and manage data in a database. It sits between the user and the database and controls all access to the data.

    Examples: MySQL, Oracle, Microsoft Access, SQL Server, PostgreSQL, SQLite.

    Why use a DBMS?

    • Faster development of applications
    • Data independence and efficient data access
    • Uniform administration of data
    • Better integrity and security
    • Concurrent access by many users and recovery after crashes
    • Easy-to-use query language (SQL)

    Functions of a DBMS

    1. Create new tables and files
    2. Insert data
    3. Retrieve (view) data
    4. Update existing data
    5. Delete data
    6. Remove tables and files

    Advantages of DBMS

    1. Reduced data redundancy
    2. Data sharing among users
    3. Improved data consistency and integrity
    4. Better data security
    5. Data independence
    6. Backup and recovery support
    7. Multiple user views
    8. Ability to answer complex queries

    Disadvantages of DBMS

    1. Costly: software, hardware, and training cost money
    2. Complex: needs skilled people to design and manage
    3. Single point of failure risk: a fault can affect many users
    4. Regular backup needed to avoid data loss
    5. Needs updating as technology changes

    4. Database Terminology and Objects

    TermMeaning
    Table (Relation)Data arranged in rows and columns
    Field (Attribute / Column)One piece of information about an item, such as Name
    Record (Tuple / Row)A complete set of fields about one item, such as one student
    EntityA real-world thing about which data is stored (student, teacher, book)
    SchemaThe overall structure of a database: tables, fields, data types, relationships, and constraints
    InstanceThe actual data stored in the database at a particular moment
    DomainThe set of allowed values for a field

    Example table: Student

    RollNoNameAddress
    1GitaNarayangarh
    2SitaGaindakot
    3ArjunBharatpur

    Here the table has 3 records, 3 fields, and RollNo can act as the primary key.

    Database objects

    ObjectPurpose
    TableBasic storage unit made of rows and columns
    QueryRetrieves or modifies data based on conditions
    FormA screen used to enter, edit, and view records
    ReportA formatted, printable output of data (view only, not editable)
    ViewA virtual table showing selected data from one or more tables
    IndexSpeeds up searching and sorting
    SequenceGenerates automatic numbers (often for IDs)

    5. Keys

    A key is a field (or group of fields) that helps identify records uniquely and link tables together.

    KeyDescription
    Primary keyUniquely identifies each record. It cannot be duplicate or NULL. A table has only one primary key.
    Candidate keyAny field (or group) that could serve as the primary key because it is unique
    Alternate keyA candidate key that was not chosen as the primary key
    Composite (compound) keyA key made of two or more fields together
    Foreign keyA field in one table that refers to the primary key of another table, creating a link

    Example:

    Student(RollNo, Email, Name)

    • Candidate keys: RollNo, Email
    • Primary key: RollNo
    • Alternate key: Email

    In a Marks(StudentID, SubjectID, Marks) table, StudentID + SubjectID together form a composite key, and each of them is also a foreign key.


    6. Database Models

    A database model defines the logical structure of a database and how data is stored, connected, and accessed.

    6.1 Hierarchical model

    Data is arranged like an upside-down tree with parent and child records. Each child has only one parent.

                College
             /     |     \
        Science Humanities Management
        /  |  \
     Physics Chemistry Biology
    
    AdvantagesDisadvantages
    Simple and easy to understandCannot represent many-to-many relationships
    Fast searching when the parent is knownSame data may be repeated (redundancy)
    Efficient for one-to-many relationshipsRigid; hard to change the structure
    Old and rarely used now

    6.2 Network model

    Records are connected like a graph. A child can have more than one parent.

    Example: An employee works in two departments, so that record links to both.

    AdvantagesDisadvantages
    Supports many-to-many relationshipsComplex structure that is difficult to design and manage
    More flexible than hierarchicalPrograms become complicated
    Fast access using links (pointers)Less secure because of widely shared links
    Reduces redundancyChanges in structure are difficult

    6.3 Relational model

    Data is stored in tables (relations) made of rows and columns. Tables are connected using keys. This is the most widely used model today (MySQL, Oracle, SQL Server).

    Example:

    Student

    RollNoName
    1Hari
    2Sita

    Marks

    RollNoSubjectMarks
    1Computer95
    2Computer85

    RollNo links the two tables.

    AdvantagesDisadvantages
    Simple, table-based and easy to understandNeeds more powerful hardware for large data
    Low redundancy (with normalization)Complex designs can need many tables and joins
    Easy to apply integrity rulesPerformance may drop with very complex queries
    Flexible; SQL makes queries easy

    6.4 Object-oriented model

    Data and its operations are stored together as objects (like objects in object-oriented programming). Supports inheritance and complex data such as images and multimedia.

    AdvantagesDisadvantages
    Handles complex data types wellComplex and has a steep learning curve
    Supports inheritance and reuseLack of a universally accepted standard
    Objects hold data and behavior togetherHigher system overhead

    Model comparison

    FeatureHierarchicalNetworkRelationalObject-oriented
    StructureTreeGraphTablesObjects
    Parents per childOneManyNot applicableNot applicable
    Many-to-manyNoYesYesYes
    Popularity todayLowLowVery highModerate

    7. Entity-Relationship (E-R) Diagram

    An E-R diagram is a graphical representation of the entities, their attributes, and the relationships in a database. It is used during database design.

    Components

    SymbolRepresents
    RectangleEntity (e.g., Student)
    Ellipse (oval)Attribute (e.g., Name)
    DiamondRelationship (e.g., Enrolls)
    LineLink connecting the components

    Types of relationships

    TypeMeaningExamples
    One-to-one (1:1)One record of A relates to only one record of BCollege тАУ Principal, Country тАУ President
    One-to-many (1:M)One record of A relates to many records of BCollege тАУ Students, Bank тАУ Employees
    Many-to-many (M:M)Many records of A relate to many records of BTeachers тАУ Students, Books тАУ Readers

    Simple text example:

    [College] ----<has>---- [Principal]        (1 : 1)
    [College] ----<has>---- [Student]          (1 : M)
    [Teacher] ----<teaches>---- [Student]      (M : M)
    

    8. Normalization

    Definition

    Normalization is the process of organizing data in a database by splitting large tables into smaller, related tables to reduce redundancy and avoid problems when inserting, updating, or deleting data.

    Note: Normalization reduces redundancy; it does not completely eliminate it, because keys must still be repeated to link tables.

    Advantages

    • Reduces data redundancy
    • Improves consistency and integrity
    • Makes table structure simpler and clearer
    • Makes the database easier to maintain

    Disadvantages

    • Design becomes more complex
    • More tables mean more joins, which can slow some queries
    • Needs more processing and storage for large systems

    Key terms for normalization

    • Atomic value: a value that cannot be divided further (one value per cell)
    • Functional dependency: field B depends on field A if knowing A tells you B (e.g., StudentID тЖТ Name)
    • Partial dependency: a non-key field depends on only part of a composite primary key
    • Transitive dependency: a non-key field depends on another non-key field, not directly on the primary key

    Normal forms

    Normal formRule
    1NFEvery field holds a single (atomic) value; no repeating groups
    2NFMust be in 1NF and have no partial dependency
    3NFMust be in 2NF and have no transitive dependency

    Worked example (1NF тЖТ 2NF тЖТ 3NF)

    Un-normalized table: Result

    StudentIDStudentNameSubjectsTeacherExamNameFullMarks
    1AnilMath, ScienceMr. Rai, Ms. GurungTerminal100
    2BinitaMathMr. RaiFinal75

    Problem: the Subjects and Teacher cells contain more than one value.

    Step 1: First Normal Form (1NF)

    Make each cell atomic by giving each subject its own row.

    StudentIDStudentNameSubjectTeacherExamNameFullMarks
    1AnilMathMr. RaiTerminal100
    1AnilScienceMs. GurungTerminal100
    2BinitaMathMr. RaiFinal75

    Primary key (composite): StudentID + Subject

    Step 2: Second Normal Form (2NF)

    Partial dependencies found:

    • StudentName depends only on StudentID
    • Teacher depends only on Subject

    Fix: split into separate tables.

    Student

    StudentIDStudentNameExamNameFullMarks
    1AnilTerminal100
    2BinitaFinal75

    Subject

    SubjectTeacher
    MathMr. Rai
    ScienceMs. Gurung

    Enrollment

    StudentIDSubject
    1Math
    1Science
    2Math

    Step 3: Third Normal Form (3NF)

    Transitive dependency found: in the Student table, FullMarks depends on ExamName, which is not the primary key (StudentID тЖТ ExamName тЖТ FullMarks).

    Fix: move exam details to their own table.

    Student

    StudentIDStudentNameExamID
    1AnilE1
    2BinitaE2

    Exam

    ExamIDExamNameFullMarks
    E1Terminal100
    E2Final75

    Result: every non-key field now depends on the primary key of its own table, and the data is stored without repeated, mixed-up details.


    9. Centralized vs Distributed Database

    Centralized database

    All data is stored at one central location (a single server). Users access it from different places.

    AdvantagesDisadvantages
    Easy to manage and maintainIf the server fails, all data may be unavailable
    Consistent data and uniform standardsHeavy load on one server slows response
    Better security controlHarder to serve very large or distant user groups
    Lower cost

    Distributed database

    Data is split or copied across several locations (sites) connected by a network, but users see it as a single database.

    AdvantagesDisadvantages
    More reliable: failure of one site does not stop everythingComplex to manage and administer
    Faster local access and load sharingExpensive to set up
    Easy to expand by adding new sitesHigher security risk because data is spread out
    Supports many usersKeeping all copies consistent is difficult

    Comparison

    BasisCentralizedDistributed
    Data locationOne siteMany sites
    ComplexitySimpleComplex
    CostLowerHigher
    ReliabilityLow (single point of failure)High
    MaintenanceEasierHarder
    Suitable forSmall organizationsLarge, multi-location organizations
    Load balancingNoYes
    Network trafficHigh towards one serverSpread across sites

    10. Data Dictionary, Integrity and Security

    Data dictionary

    A data dictionary is a store of metadata ("data about data"). It describes table names, field names, data types, sizes, keys, relationships, and user access rights. It is also called the system catalog.

    Data integrity

    Data integrity means the data in the database is accurate, valid, and consistent.

    Integrity typeMeaning
    Domain integrityValues in a field must be within the allowed range or type (e.g., age must be a number; marks 0тАУ100)
    Entity integrityEvery record must be uniquely identifiable; primary key must be unique and not null
    Referential integrityA foreign key value must match an existing primary key value in the related table (or be null)

    Data security

    Data security means protecting the database from unauthorized access, modification, loss, or destruction. It is done through passwords, user privileges, encryption, backups, and firewalls.


    11. Database Administrator (DBA)

    Definition

    A Database Administrator (DBA) is the person responsible for the overall design, management, security, and performance of the database system in an organization.

    Responsibilities

    1. Install, configure, and upgrade the DBMS
    2. Design and create the database structure
    3. Give and control user access rights
    4. Take backups and perform recovery after failure
    5. Monitor performance and fix problems
    6. Maintain security and integrity of data
    7. Train users on how to use the database

    Qualities of a good DBA

    • Strong knowledge of DBMS software (MySQL, Oracle, etc.)
    • Knowledge of the operating system and networking
    • Good database design and problem-solving skills
    • Honesty and responsibility, since the DBA handles sensitive data

    12. SQL (Structured Query Language)

    Definition

    SQL is the standard language used to create, manage, and query relational databases.

    Features

    • Easy, English-like commands
    • Non-procedural: you say what you want, not how to get it
    • Works on single records or sets of records
    • Used to define tables, views, security, and transactions
    • Supported by almost all relational DBMSs

    Categories of SQL commands

    CategoryFull formPurposeCommands
    DDLData Definition LanguageDefine or change the structure of database objectsCREATE, ALTER, DROP, TRUNCATE, RENAME
    DMLData Manipulation LanguageWork with the data inside tablesSELECT, INSERT, UPDATE, DELETE
    DCLData Control LanguageControl access and permissionsGRANT, REVOKE

    Note: In many textbooks, transaction commands COMMIT and ROLLBACK are grouped under DCL. In standard SQL they belong to TCL (Transaction Control Language). Write them under DCL if your syllabus says so.

    DDL commands

    CommandUse
    CREATECreates a database or table
    ALTERChanges the structure of a table
    DROPDeletes a database or table completely
    TRUNCATERemoves all records but keeps the table structure
    RENAMERenames an object

    DML commands

    CommandUse
    SELECTRetrieves data
    INSERTAdds new records
    UPDATEModifies existing records
    DELETERemoves records

    SQL statements with examples

    Create and delete a database

    CREATE DATABASE School;
    DROP DATABASE School;
    

    Create a table

    CREATE TABLE Students (
        StudentID INT PRIMARY KEY,
        FName     VARCHAR(50),
        LName     VARCHAR(50),
        Address   VARCHAR(100),
        Class     INT
    );
    

    Alter a table

    -- Add a column
    ALTER TABLE Students ADD Email VARCHAR(100);
    
    -- Delete a column
    ALTER TABLE Students DROP COLUMN Email;
    
    -- Change a column's data type (MySQL syntax)
    ALTER TABLE Students MODIFY COLUMN Class VARCHAR(10);
    

    Delete a table

    DROP TABLE Students;
    

    Insert data

    INSERT INTO Students (StudentID, FName, LName, Address, Class)
    VALUES (101, 'Ram', 'Sharma', 'Pokhara', 7);
    

    Select data

    -- All columns
    SELECT * FROM Students;
    
    -- Specific columns
    SELECT FName, LName FROM Students;
    
    -- With a condition
    SELECT * FROM Students WHERE Class = 7;
    

    Update data

    UPDATE Students
    SET Address = 'Kathmandu'
    WHERE StudentID = 101;
    

    Delete data

    DELETE FROM Students
    WHERE StudentID = 101;
    

    Warning: Always use WHERE with UPDATE and DELETE. Without it, all records are changed or removed.

    Grant and revoke permissions

    GRANT SELECT, INSERT ON Students TO 'user1';
    REVOKE INSERT ON Students FROM 'user1';
    

    Tip: In MySQL/XAMPP (phpMyAdmin), run these statements from the SQL tab.


    13. Quick Revision Table

    TopicKey point
    DataRaw facts without meaning
    InformationProcessed, meaningful data
    DatabaseOrganized collection of related data
    DBMSSoftware to create and manage a database
    Primary keyUnique, non-null identifier of a record
    Foreign keyField linking to another table's primary key
    Hierarchical modelTree; one parent per child
    Network modelGraph; many parents allowed
    Relational modelTables linked by keys; most popular
    E-R diagramEntities, attributes, relationships
    1NFAtomic values
    2NF1NF + no partial dependency
    3NF2NF + no transitive dependency
    Data dictionaryMetadata (data about data)
    DBAManages and secures the database
    DDLCREATE, ALTER, DROP, TRUNCATE, RENAME
    DMLSELECT, INSERT, UPDATE, DELETE
    DCLGRANT, REVOKE

    14. Practice Questions

    Short-answer questions

    1. Differentiate between data and information.
    2. What is a database? What is a DBMS? Give two examples of DBMS software.
    3. Write any four limitations of the file-based system.
    4. Define the following: (a) data dictionary (b) primary key (c) relationship (d) DML (e) SQL (f) data integrity (g) DDL (h) data security (i) database system
    5. Differentiate between a primary key, a candidate key, and a foreign key.
    6. Write any four responsibilities of a DBA.
    7. What is a schema? How is it different from an instance?

    Long-answer questions

    1. What is a database and DBMS? Write the advantages and disadvantages of DBMS.
    2. Explain the different database models with their advantages and disadvantages.
    3. Differentiate between centralized and distributed database systems.
    4. Who is a DBA? Explain the major responsibilities and qualities of a DBA.
    5. What is normalization? Explain 1NF, 2NF, and 3NF with examples.
    6. Explain the types of data integrity constraints.
    7. Draw an E-R diagram for a college and its students/teachers, and explain the types of relationships.

    SQL practice

    Given the table Students(StudentID, FName, LName, Address, Class), write SQL statements to:

    1. Create the table.
    2. Add a column Phone.
    3. Insert two records.
    4. Display all students of Class 10.
    5. Change the address of student 101 to Chitwan.
    6. Delete the record of student 102.

    Fill in the blanks

    1. A key that cannot contain NULL values is the ______ key. (primary)
    2. In the ______ model, a child can have more than one parent. (network)
    3. A table in 2NF must not have ______ dependency. (partial)
    4. ______ is data about data. (Metadata)
    5. The SQL command used to remove all records but keep the table structure is ______. (TRUNCATE)

    Prepared for NEB Class 12 Computer Science exam revision. Always cross-check key definitions with your prescribed textbook and your teacher's guidance.