Skip to content

DBMS & SQL

DSSSB TGT CS — Section B P2 (Rank ~9). Focus: keys, NF, ACID, SQL clauses, joins, MySQL functions.


1. DBMS vs File System

File systemDBMS
DataApplication-owned filesCentralized managed data
RedundancyHigh / uncontrolledControlled
IntegrityApp responsibilityConstraints, transactions
ConcurrencyHardManaged (locks/isolation)
QueryCustom codeDeclarative SQL
SecurityOS-level mainlyFine-grained users/roles

DBMS = software to define, create, maintain, and control access to databases.


2. Data Models

ModelIdea
HierarchicalTree (parent–child)
NetworkGraph / many-many via links
RelationalTables (relations) — dominant exam focus
Object / Object-relationalObjects + relations
Document / NoSQLFlexible documents (awareness)

3. Relational Terms

TermMeaning
RelationTable
AttributeColumn
TupleRow
DomainAllowed value set for an attribute
DegreeNumber of attributes (columns)
CardinalityNumber of tuples (rows)
SchemaStructure definition
InstanceData at a moment

4. Keys

KeyDefinition
Super keySet of attributes that uniquely identify a tuple
Candidate keyMinimal super key
Primary keyChosen candidate key (no NULL)
Alternate keyCandidate keys not chosen as PK
Foreign keyAttribute(s) referencing PK/unique of another (or same) relation
  • Composite key = multi-attribute key.
  • Trap: Every candidate key is a super key; not every super key is candidate (may have extras).

5. Normalization (brief)

FormRule (exam level)
1NFAtomic values; no repeating groups
2NF1NF + no partial dependency on part of composite PK
3NF2NF + no transitive dependency (non-key → non-key)
BCNFFor every FD X→Y, X is a super key (stricter than 3NF)

Goal: reduce redundancy and update anomalies.

  • Trap: BCNF is stricter than 3NF; a relation can be 3NF but not BCNF.

6. ACID

PropertyMeaning
AtomicityAll-or-nothing transaction
ConsistencyDB moves between valid states
IsolationConcurrent txns don’t interfere wrongly
DurabilityCommitted data survives crashes

7. SQL Language Groups

GroupPurposeExamples
DDLStructureCREATE, ALTER, DROP, TRUNCATE
DMLDataINSERT, UPDATE, DELETE, SELECT*
DCLAccessGRANT, REVOKE
TCLTransactionsCOMMIT, ROLLBACK, SAVEPOINT

*Some classify SELECT as DQL; many exam keys still put it under DML/query.


8. Core SQL Statements

sql
CREATE TABLE Student(id INT PRIMARY KEY, name VARCHAR(50), age INT);
ALTER TABLE Student ADD marks INT;
DROP TABLE Student;

INSERT INTO Student VALUES (1,'Asha',15);
UPDATE Student SET age=16 WHERE id=1;
DELETE FROM Student WHERE id=1;

SELECT name, age FROM Student WHERE age > 14 ORDER BY name;

JOIN types

JoinResult
INNERMatching rows only
LEFT OUTERAll left + matches (NULL if none)
RIGHT OUTERAll right + matches
FULL OUTERAll from both (NULLs where no match)
CROSSCartesian product

9. Aggregates & GROUP BY

FunctionRole
COUNTNumber of rows/values
SUMTotal
AVGAverage
MIN / MAXExtremes
sql
SELECT dept, COUNT(*) FROM Emp GROUP BY dept HAVING COUNT(*) > 5;
  • WHERE filters rows before grouping; HAVING filters groups.
  • Trap: Non-aggregated SELECT columns must appear in GROUP BY (standard SQL).

10. MySQL Functions (exam-common)

String

FnUse
CONCAT, LENGTH / CHAR_LENGTHJoin / length
UPPER, LOWERCase
SUBSTRING / SUBSTRSlice
TRIM, LTRIM, RTRIMSpaces
REPLACEReplace substring

Math

FnUse
ABS, CEIL, FLOOR, ROUNDRounding family
MOD, POW / POWER, SQRTArithmetic

Date

FnUse
NOW(), CURDATE(), CURTIME()Current
YEAR, MONTH, DAYExtract
DATE_ADD, DATE_SUB, DATEDIFFArithmetic / difference

11. Views & Indexes

ConceptIdea
ViewVirtual table from a query; stored definition, not (usually) base data
IndexAuxiliary structure (e.g. B-tree) to speed lookups — tradeoff: space + slower writes
  • Views simplify queries and can hide columns.
  • Primary key typically auto-indexed.

12. ER Diagram Symbols (exam)

SymbolMeaning
RectangleEntity set
Ellipse / ovalAttribute
DiamondRelationship
Double ellipseMultivalued attribute
Dashed ellipseDerived attribute
Double rectangleWeak entity
UnderlinePrimary key attribute
LinesLinks entity–attribute / entity–relationship

Cardinality notations: 1:1, 1:N, M:N (crow’s foot or labeled).


Quick Revision Traps

  1. Degree = columns; cardinality = rows.
  2. FK references PK/unique — enforces referential integrity.
  3. WHERE vs HAVING.
  4. DELETE removes rows; DROP removes table; TRUNCATE empties table (DDL-ish).
  5. 2NF about partial dependency; 3NF about transitive.
  6. ACID → transaction reliability, not normalization.