Introduction to Database Concept Class 12 Notes

Last updated on June 27th, 2026 at 09:28 am

Introduction to DBMS and MySQL Notes Class 12 β€” This page covers the complete CBSE Class 12 Computer Science (Code 083) database unit β€” from basic database concepts and terminology to SQL commands, constraints, aggregate functions, and practical MySQL queries. All topics are explained clearly with definitions, examples, and board-exam-style questions so you can score maximum marks.

πŸ’‘ Exam tip: Database questions appear every year in the CBSE Class 12 board paper β€” usually 8–10 marks worth of SQL queries, definitions, and output-based questions. Focus on: DDL vs DML difference, SQL constraints, SELECT with WHERE/ORDER BY/GROUP BY, and aggregate functions. Practise every query in the online MySQL terminal.

Quick Overview β€” What You Will Learn

#TopicKey ConceptsWeight
1What is a Database?Data, Information, Database, DBMS, Advantages⭐⭐
2Key Database TerminologyTable, Record, Field, Tuple, Attribute, Domain⭐⭐
3Types of KeysPrimary Key, Candidate Key, Alternate Key, Foreign Key⭐⭐⭐
4DBMS vs RDBMSDifferences, Examples, Codd’s Rules⭐⭐
5Introduction to MySQLFeatures, Data Types, CHAR vs VARCHAR⭐⭐
6SQL Command CategoriesDDL, DML, DCL, TCL β€” with examples⭐⭐⭐
7SQL ConstraintsNOT NULL, UNIQUE, DEFAULT, PRIMARY KEY, FOREIGN KEY, CHECK⭐⭐⭐
8CREATE TABLE & INSERTTable creation, inserting rows⭐⭐⭐
9SELECT Command*, columns, WHERE, DISTINCT, ORDER BY, BETWEEN, LIKE, IN⭐⭐⭐
10Aggregate FunctionsCOUNT(), SUM(), AVG(), MAX(), MIN()⭐⭐⭐
11GROUP BY & HAVINGGrouping records, filtering groups⭐⭐⭐
12UPDATE & DELETEModifying and removing rows⭐⭐
13ALTER TABLEADD, DROP, MODIFY column, constraints⭐⭐⭐

Section 1Theory ⭐⭐

πŸ—„οΈ What is a Database?

A database is an organised, structured collection of related data that can be easily stored, accessed, managed, and updated. Unlike a random collection of data, a database organises information in a way that makes retrieval quick and reliable. A Database Management System (DBMS) is the software that manages the database and provides tools to create, read, update, and delete data.

Important Definitions

  • Data: Raw, unprocessed facts and figures. Example: 95, “Arjun”, “Delhi”.
  • Information: Processed, meaningful data. Example: “Arjun scored 95 marks and lives in Delhi.”
  • Database: An organised collection of related data stored and accessed electronically.
  • DBMS: Software that creates, manages, and controls access to a database. Example: MySQL, Oracle, MS Access.
  • RDBMS: A DBMS that organises data into related tables and supports SQL. Example: MySQL, PostgreSQL, Oracle.

Advantages of a Database over Traditional File System

  • Reduced data redundancy β€” Same data is not stored multiple times unnecessarily.
  • Data consistency β€” Updating data in one place reflects everywhere automatically.
  • Data sharing β€” Multiple users and applications can access the same data simultaneously.
  • Data security β€” Access can be restricted using user roles and passwords.
  • Data integrity β€” Constraints ensure only valid, accurate data is stored.
  • Easy backup and recovery β€” Databases support automated backup and restore features.
  • Data independence β€” Changes to data structure do not affect applications using the data.
DataInformationDatabaseDBMSRDBMSData Redundancy

Section 2Theory ⭐⭐

πŸ“‹ Key Database Terminology

Before writing SQL queries, you must understand the key terms used to describe the structure of a relational database. These definitions are frequently asked as 1-mark or 2-mark questions in CBSE board exams.
TermDefinitionExample
Table (Relation)A collection of related data organised in rows and columns. The basic unit of storage in an RDBMS.STUDENT table
Record (Row / Tuple)A single, complete entry in a table. One row represents one entity.Details of one student
Field (Column / Attribute)A single piece of information about an entity. One column in a table.RollNo, Name, Marks
DomainThe set of all valid values that an attribute can hold.Marks: 0 to 100
DegreeThe total number of columns (attributes / fields) in a table.STUDENT has 5 columns β†’ Degree = 5
CardinalityThe total number of rows (records / tuples) in a table.STUDENT has 30 rows β†’ Cardinality = 30
πŸ’‘ Remember for Exams:
  • Row = Record = Tuple β€” all three mean the same thing.
  • Column = Field = Attribute β€” all three mean the same thing.
  • Degree = number of columns. Cardinality = number of rows.
TableRecord / TupleField / AttributeDomainDegreeCardinality

Section 3Theory ⭐⭐⭐

πŸ”‘ Types of Keys in RDBMS

A key is a field (or combination of fields) that uniquely identifies a record in a table. Keys are fundamental to the relational model β€” they establish relationships between tables and ensure data integrity. This is a very commonly asked 2–3 mark definition + example topic in CBSE board exams.
Key TypeDefinitionExample
Primary KeyA field (or combination) that uniquely identifies each record in a table. Cannot be NULL or duplicate.RollNo in STUDENT table
Candidate KeyAny field (or combination) that is capable of being a primary key β€” unique and not null. A table can have multiple candidate keys.RollNo, AdmissionNo (both can uniquely identify a student)
Alternate KeyAll candidate keys that are NOT chosen as the primary key. They are “alternatives” to the primary key.If RollNo is Primary Key, then AdmissionNo is Alternate Key
Foreign KeyA field in one table that references the Primary Key of another table. Used to establish relationships between tables and enforce referential integrity.RollNo in MARKS table referencing RollNo in STUDENT table
Composite KeyA primary key made up of two or more fields together β€” no single field can uniquely identify a record alone.(StudentID + SubjectCode) together as primary key in RESULT table
πŸ’‘ Key Relationships to Remember:
  • Every Primary Key is a Candidate Key, but not every Candidate Key is a Primary Key.
  • Alternate Key = Candidate Key βˆ’ Primary Key.
  • A Foreign Key in one table must match an existing Primary Key value in the referenced table.
  • A table can have only one Primary Key but multiple Candidate Keys and Alternate Keys.
Primary KeyCandidate KeyAlternate KeyForeign KeyComposite Key

Section 4Theory ⭐⭐

βš–οΈ DBMS vs RDBMS

Both DBMS and RDBMS are database management systems, but they differ in how data is stored, related, and protected. This comparison is a standard 2-mark question in CBSE board exams.
FeatureDBMSRDBMS
Data StorageStores data as files (hierarchical or network model)Stores data in related tables (rows and columns)
Data RelationshipsNo formal relationship between dataTables are related using primary and foreign keys
Data RedundancyHigh β€” same data may be repeated across filesLow β€” normalisation reduces redundancy
SecurityLimited security featuresStrong security with user roles and access control
SQL SupportDoes not necessarily support SQLFully supports SQL (Structured Query Language)
Data IntegrityNo built-in integrity constraintsEnforces integrity through keys and constraints
ExamplesMS Access (flat file), XML databasesMySQL, Oracle, PostgreSQL, MS SQL Server
DBMSRDBMSTablesSQLNormalisationReferential Integrity

Section 5Theory + Practical ⭐⭐

πŸ—„οΈ Introduction to MySQL β€” Data Types

MySQL is an open-source Relational Database Management System (RDBMS) that uses SQL to manage data. It stores data in tables and is one of the most widely used databases in the world. Every column in a MySQL table must have a data type that defines what kind of data it can store.
Data TypeDescriptionExample
INTWhole numbers. Range: βˆ’2,147,483,648 to 2,147,483,647. Occupies 4 bytes.RollNo INT
FLOATDecimal numbers with approximate precision. Occupies 4 bytes.Marks FLOAT
DECIMAL(M,D)Exact decimal numbers. M = total digits, D = digits after decimal point.Salary DECIMAL(8,2)
CHAR(M)Fixed-length string. Always stores exactly M characters (pads with spaces). Max 255.Gender CHAR(1)
VARCHAR(M)Variable-length string. Stores only actual characters entered. Max 65,535. M is compulsory.Name VARCHAR(30)
DATEDate in YYYY-MM-DD format. Range: 1000-01-01 to 9999-12-31.DOB DATE

CHAR vs VARCHAR β€” Most Asked Comparison

FeatureCHAR(M)VARCHAR(M)
TypeFixed-length stringVariable-length string
StorageAlways stores exactly M bytes (pads with spaces if shorter)Stores only actual characters entered β€” no padding
Max Length255 characters65,535 characters
M parameterOptional (default is 1)Compulsory β€” must be specified
Best ForFixed-size data: Gender (M/F), Grade (A/B/C)Variable-size data: Name, Email, Address
Memory trick: CHAR(10) storing “Hi” uses 10 bytes (pads with 8 spaces). VARCHAR(10) storing “Hi” uses only 2 bytes (no padding). VARCHAR is more storage-efficient for variable-length data.
INTFLOATDECIMALCHARVARCHARDATE

Section 6Theory ⭐⭐⭐

πŸ“ SQL Command Categories

SQL commands are grouped into categories based on what they do. CBSE Class 12 expects you to know three main categories β€” DDL, DML, and TCL/DCL β€” with examples. “Give the full form of DDL and list two DDL commands” is a standard 2-mark board question.

DDL β€” Data Definition Language

DDL commands work on the structure (schema) of the database β€” creating, modifying, and deleting tables and databases.

CommandPurposeExample
CREATE DATABASECreates a new databaseCREATE DATABASE School;
CREATE TABLECreates a new tableCREATE TABLE Student (…);
ALTER TABLEModifies an existing table structureALTER TABLE Student ADD Grade CHAR(1);
DROP TABLEPermanently deletes a table and all its dataDROP TABLE Student;

DML β€” Data Manipulation Language

DML commands work on the data (rows) inside tables β€” inserting, reading, updating, and deleting records.

CommandPurposeExample
SELECTRetrieves data from a tableSELECT * FROM Student;
INSERT INTOAdds new rows into a tableINSERT INTO Student VALUES (…);
UPDATEModifies existing rows in a tableUPDATE Student SET Marks=90 WHERE RollNo=101;
DELETERemoves rows from a tableDELETE FROM Student WHERE RollNo=101;

TCL / DCL β€” Transaction and Data Control Language

CommandTypePurpose
COMMITTCLPermanently saves all changes made in the current transaction
ROLLBACKTCLUndoes all changes made in the current transaction
GRANTDCLGives a user permission to perform specific database operations
REVOKEDCLTakes back permissions previously given to a user
πŸ’‘ Key Distinction β€” Exam Trick:
  • DDL works on table structure (schema) β€” CREATE, ALTER, DROP.
  • DML works on table data (rows) β€” SELECT, INSERT, UPDATE, DELETE.
  • SELECT is a DML command, not DDL β€” very common trick question in exams.
  • DROP TABLE β‰  DELETE β€” DROP removes the table itself; DELETE removes rows from the table.
DDLDMLTCLDCLCREATEALTERSELECTINSERT

Section 7Theory + Practical ⭐⭐⭐

πŸ”’ SQL Constraints

Constraints are rules applied to table columns to restrict the type of data that can be stored. They maintain the accuracy, integrity, and reliability of data. If a constraint is violated, the database rejects the operation with an error. Constraints are defined either during CREATE TABLE or added later using ALTER TABLE.
ConstraintWhat It DoesExample
NOT NULLColumn cannot store NULL values β€” a value must always be provided.Name VARCHAR(30) NOT NULL
UNIQUEAll values in the column must be different. No two rows can have the same value.Email VARCHAR(50) UNIQUE
DEFAULTAssigns a default value if no value is provided during INSERT.City VARCHAR(20) DEFAULT ‘Delhi’
PRIMARY KEYUniquely identifies each row. Combines NOT NULL + UNIQUE. Only one per table.RollNo INT PRIMARY KEY
FOREIGN KEYLinks a column to the PRIMARY KEY of another table. Enforces referential integrity.FOREIGN KEY(RollNo) REFERENCES Student(RollNo)
CHECKEnsures column values satisfy a specific condition or range.Marks FLOAT CHECK(Marks >= 0 AND Marks <= 100)
NOT NULLUNIQUEDEFAULTPRIMARY KEYFOREIGN KEYCHECK

Section 8Practical ⭐⭐⭐

πŸ“‹ CREATE TABLE and INSERT INTO

CREATE TABLE

SYNTAX CREATE TABLE <TableName> ( <Column1> <DataType> [Constraint], <Column2> <DataType> [Constraint], … );EXAMPLE CREATE TABLE STUDENT ( RollNo INT PRIMARY KEY, Name VARCHAR(30) NOT NULL, Class CHAR(3), Gender VARCHAR(10) DEFAULT ‘Male’, DOB DATE, Marks FLOAT CHECK(Marks >= 0 AND Marks <= 100) );

INSERT INTO

SYNTAX INSERT INTO <TableName> (<Col1>, <Col2>, …) VALUES (<Val1>, <Val2>, …);EXAMPLE INSERT INTO STUDENT (RollNo, Name, Class, Gender, DOB, Marks) VALUES (101, ‘Arjun Sharma’, ’12A’, ‘Male’, ‘2006-04-15’, 87.5);INSERT INTO STUDENT (RollNo, Name, Class, DOB, Marks) VALUES (102, ‘Priya Sharma’, ’12B’, ‘2006-08-22’, 92.0); — Gender uses DEFAULT value ‘Male’ since not specified
CREATE TABLEINSERT INTOVALUESDEFAULT

Section 9Practical ⭐⭐⭐

πŸ” SELECT Command β€” Retrieving Data

The SELECT command retrieves data from one or more tables. It is the most commonly tested SQL command in CBSE board exams β€” questions include writing queries, predicting output, and identifying errors. Mastering SELECT is essential for scoring well.

Display All Columns and All Rows

EXAMPLE SELECT * FROM STUDENT;

Display Selected Columns

EXAMPLE SELECT Name, Marks FROM STUDENT;

WHERE β€” Filter Rows by Condition

EXAMPLE SELECT * FROM STUDENT WHERE Marks > 80; SELECT Name, Marks FROM STUDENT WHERE Class = ’12A’; SELECT * FROM STUDENT WHERE Gender = ‘Female’ AND Marks >= 90;

BETWEEN β€” Range Condition

EXAMPLE SELECT * FROM STUDENT WHERE Marks BETWEEN 70 AND 90; — Includes both 70 and 90 (inclusive)

LIKE β€” Pattern Matching

EXAMPLE SELECT * FROM STUDENT WHERE Name LIKE ‘A%’; — Names starting with A SELECT * FROM STUDENT WHERE Name LIKE ‘%Kumar’; — Names ending with Kumar SELECT * FROM STUDENT WHERE Name LIKE ‘_r%’; — Names with ‘r’ as second character

IN β€” Match from a List

EXAMPLE SELECT * FROM STUDENT WHERE Class IN (’12A’, ’12B’); — Same as: WHERE Class=’12A’ OR Class=’12B’

DISTINCT β€” Remove Duplicate Values

EXAMPLE SELECT DISTINCT Class FROM STUDENT; — Each class name shown only once

ORDER BY β€” Sort Results

EXAMPLE SELECT Name, Marks FROM STUDENT ORDER BY Marks; — Ascending (default) SELECT Name, Marks FROM STUDENT ORDER BY Marks DESC; — Descending SELECT * FROM STUDENT ORDER BY Class ASC, Marks DESC; — Sort by Class ASC, then Marks DESC
SELECT *WHEREBETWEENLIKEINDISTINCTORDER BY

Section 10Practical ⭐⭐⭐

πŸ“Š Aggregate Functions

Aggregate functions perform calculations on a set of values and return a single result. They are used with SELECT to summarise data β€” for example, finding the total marks, average score, or number of students. These functions ignore NULL values (except COUNT(*)).
FunctionWhat it DoesExample
COUNT()Counts the number of rows. COUNT(*) counts all rows including NULLs. COUNT(column) ignores NULLs.SELECT COUNT(*) FROM STUDENT;
SUM()Returns the total sum of a numeric column.SELECT SUM(Marks) FROM STUDENT;
AVG()Returns the average value of a numeric column.SELECT AVG(Marks) FROM STUDENT;
MAX()Returns the highest value in a column.SELECT MAX(Marks) FROM STUDENT;
MIN()Returns the lowest value in a column.SELECT MIN(Marks) FROM STUDENT;
EXAMPLES SELECT COUNT(*) FROM STUDENT; — Total number of students SELECT COUNT(*) FROM STUDENT WHERE Class = ’12A’; — Students in class 12A SELECT SUM(Marks) FROM STUDENT; — Total of all marks SELECT AVG(Marks) FROM STUDENT; — Average marks SELECT MAX(Marks), MIN(Marks) FROM STUDENT; — Highest and lowest marks SELECT MAX(Marks) FROM STUDENT WHERE Class = ’12B’; — Highest marks in class 12B
COUNT()SUM()AVG()MAX()MIN()

Section 11Practical ⭐⭐⭐

πŸ“¦ GROUP BY and HAVING

GROUP BY groups rows that have the same value in a specified column and applies aggregate functions to each group separately. HAVING filters groups after grouping β€” it is the WHERE clause for groups. Remember: WHERE filters individual rows (before grouping), HAVING filters groups (after grouping).

GROUP BY

EXAMPLE — Count students in each class SELECT Class, COUNT(*) FROM STUDENT GROUP BY Class;— Average marks per class SELECT Class, AVG(Marks) FROM STUDENT GROUP BY Class;— Highest marks per class SELECT Class, MAX(Marks) FROM STUDENT GROUP BY Class;

HAVING β€” Filter Groups

EXAMPLE — Show only classes with more than 10 students SELECT Class, COUNT(*) FROM STUDENT GROUP BY Class HAVING COUNT(*) > 10;— Classes where average marks exceed 75 SELECT Class, AVG(Marks) FROM STUDENT GROUP BY Class HAVING AVG(Marks) > 75;
πŸ’‘ WHERE vs HAVING β€” Most Asked Difference:
  • WHERE filters individual rows before grouping. Cannot use aggregate functions in WHERE.
  • HAVING filters groups after GROUP BY. Can use aggregate functions in HAVING.
  • Example: WHERE Marks > 60 filters rows. HAVING AVG(Marks) > 60 filters groups.
GROUP BYHAVINGWHERE vs HAVINGAggregate + GROUP BY

Section 12Practical ⭐⭐

✏️ UPDATE and DELETE

UPDATE β€” Modify Existing Rows

SYNTAX UPDATE <TableName> SET <Column> = <Value> [WHERE <Condition>];EXAMPLES UPDATE STUDENT SET Marks = 95 WHERE RollNo = 101; UPDATE STUDENT SET Class = ’12C’, Marks = 88 WHERE RollNo = 102;
⚠️ Always use WHERE with UPDATE. UPDATE STUDENT SET Marks = 95 without WHERE will update every single row in the table.

DELETE β€” Remove Rows

SYNTAX DELETE FROM <TableName> [WHERE <Condition>];EXAMPLES DELETE FROM STUDENT WHERE RollNo = 101; DELETE FROM STUDENT WHERE Marks < 33; — Delete all failed students
⚠️ Always use WHERE with DELETE. DELETE FROM STUDENT without WHERE permanently deletes every row from the table.
UPDATESETDELETE FROMWHERE clause

Section 13Practical ⭐⭐⭐

πŸ”§ ALTER TABLE

The ALTER TABLE command modifies the structure of an existing table β€” without deleting and recreating it. You can add columns, drop columns, change data types, and add or remove constraints. This is a DDL command and is one of the most frequently asked commands in CBSE board exams β€” usually as a “write the SQL command to…” question.

Add a New Column

EXAMPLE ALTER TABLE STUDENT ADD Grade CHAR(1);

Remove a Column

EXAMPLE ALTER TABLE STUDENT DROP DOB;

Modify Data Type of a Column

EXAMPLE ALTER TABLE STUDENT MODIFY Name VARCHAR(50);

Add PRIMARY KEY

EXAMPLE ALTER TABLE STUDENT ADD PRIMARY KEY(RollNo);

Drop PRIMARY KEY

EXAMPLE ALTER TABLE STUDENT DROP PRIMARY KEY;

Add FOREIGN KEY

EXAMPLE ALTER TABLE MARKS ADD FOREIGN KEY(RollNo) REFERENCES STUDENT(RollNo);

Add UNIQUE Constraint

EXAMPLE ALTER TABLE STUDENT ADD UNIQUE(Email);

Add DEFAULT Constraint

EXAMPLE ALTER TABLE STUDENT MODIFY Gender VARCHAR(10) DEFAULT ‘Male’;
ADD columnDROP columnMODIFYADD PRIMARY KEYADD FOREIGN KEYADD UNIQUEADD DEFAULT

Frequently Asked Questions

What is the difference between DDL and DML commands?
DDL (Data Definition Language) commands work on the structure (schema) of the database β€” they create, modify, or delete tables. Examples: CREATE, ALTER, DROP. DML (Data Manipulation Language) commands work on the data (rows) inside tables. Examples: SELECT, INSERT, UPDATE, DELETE. Important trick: SELECT is DML, not DDL.
What is the difference between WHERE and HAVING?
WHERE filters individual rows before grouping and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregate functions. Example: WHERE Marks > 60 filters rows before any grouping; HAVING AVG(Marks) > 60 filters groups after GROUP BY.
What is the difference between PRIMARY KEY and UNIQUE constraint?
Both ensure all values in a column are distinct. However, PRIMARY KEY also enforces NOT NULL β€” it cannot have NULL values. A table can have only one PRIMARY KEY but multiple UNIQUE constraints. The primary key is the main row identifier; UNIQUE is applied to other columns that must not have duplicates (like email or phone number).
What is the difference between DROP TABLE and DELETE?
DROP TABLE is a DDL command that permanently deletes the entire table β€” both its structure and all its data. The table no longer exists after DROP. DELETE is a DML command that removes specific rows from a table while keeping the table structure intact. You can filter which rows to delete using WHERE.
What is a Foreign Key and why is it used?
A Foreign Key is a column in one table that references the Primary Key of another table. It enforces referential integrity β€” you cannot insert a value in the foreign key column that does not exist in the referenced table. This prevents orphan records and keeps data consistent across related tables.
What is the difference between Candidate Key and Alternate Key?
A Candidate Key is any field (or combination) that can uniquely identify each row in a table β€” it is unique and not null. A table can have multiple candidate keys. The one chosen as the main identifier becomes the Primary Key. All remaining candidate keys that were NOT chosen as the primary key are called Alternate Keys. In short: Alternate Key = Candidate Key βˆ’ Primary Key.
What is the use of the LIKE operator in SQL?
The LIKE operator is used for pattern matching in string columns with two wildcards β€” % (matches any sequence of characters, including zero characters) and _ (matches exactly one character). Examples: LIKE 'A%' matches names starting with A; LIKE '%Kumar' matches names ending with Kumar; LIKE '_r%' matches names where the second character is ‘r’.

Quick Practice Links

Explore More Resources for Class 12 Computer Science

Leave a Comment