Docsity

DBMS Complete Study Notes – SQL, ER Model, Normalization & Transactions, Study notes of Distributed Database Management Systems

Partial preview of the text

Download DBMS Complete Study Notes – SQL, ER Model, Normalization & Transactions and more Study notes Distributed Database Management Systems in PDF only on Docsity!

E X A M - R E A D Y S T U D Y N O T E S · B. T E C H C O M P U T E R S C I E N C E

DBMS

Complete Study Notes

Database Management Systems

Concepts • SQL • ER Model • Normalization • Transactions • Recovery • Indexing

id | name | dep

101 | Asha | CS

102 | Ravi | EC

20 chapters · revision sheets · SQL practice Original notes for self-study

Contents

Chapters follow the order of a typical DBMS course: design first, then SQL, then theory of good design, then transactions and storage.

F O U N DAT I O N S

1 Introduction to DBMS

2 DBMS Architecture

3 Data Models and Database Types

D E S I G N I N G A DATA B A S E

4 The ER Model

5 Enhanced ER Model

6 The Relational Model

7 Keys and Constraints

8 ER to Relational Mapping

Q U E R Y I N G

9 Relational Algebra

10 SQL Fundamentals

11 SQL Queries

12 Joins, Subqueries, Set Operations

13 Views and Advanced SQL

G O O D D E S I G N 14 Functional Dependencies

15 Normalization

R E L I A B I L I T Y A N D S P E E D 16 Transactions

17 Concurrency Control

18 Recovery

19 File Organization and Indexing

20 Scaling, Distributed DBs and NoSQL

L A S T- M I N U T E R Quick Revision Section

How to read: boxes marked Remember, Exam Tip, Common Mistake and Quick Revision pick out the lines that exam answers are built from. SQL examples use MySQL-style syntax and one running schema (Student, Department, Course, Enrollment) so you can retype them and see the results. To make a PDF, use your browser's Print command, choose A 4 and turn on background graphics.

1.3 Why not just use files?

Early systems kept data in separate files owned by separate programs. That approach creates seven classic problems, and each one is a reason to use a DBMS.

Problem in a file system What goes wrong How a DBMS helps

Redundancy and inconsistency

The same address is stored in three files and only one gets corrected.

One central copy; controlled sharing.

Difficult data access A new question needs a new program. Query language such as SQL. Data isolation Data sits in files of different formats. One uniform model and format.

Integrity problems Nothing stops a negative stock level. Declared constraints enforced automatically. Atomicity problems A crash after debit but before credit loses money.

Transactions: all or nothing.

Concurrent-access anomalies

Two clerks update one balance at once; one update vanishes.

Concurrency control and isolation. Security problems Anyone with the file sees everything. Users, roles, privileges and views.

🎯 Exam Tip The seven problems above double as the answer to "Advantages of DBMS" and "Why do we use a DBMS?". Write all seven with a one-line example each for full marks.

1.4 DBMS compared with a file system

Feature File system DBMS

Redundancy High Low and controlled Data sharing Hard Built in for many users

Consistency Left to the programmer Enforced by constraints

Backup and recovery Manual Automatic logging and recovery Security Operating-system permissions only Fine-grained privileges

Querying Custom code Declarative language Cost and complexity Low Higher: software, hardware, training

1.5 Who uses a database?

END USERS

Naive users run ready-made forms and apps (a bank customer). Casual users write ad-hoc queries (a manager).

APPLICATION
PROGRAMMERS

Write the programs that call the database through embedded SQL or APIs.

DATABASE DESIGNERS

Decide what data to store and how it is structured.

DATABASE
ADMINISTRATOR

Holds central control of data and of the programs that access it.

Responsibilities of the DBA

Schema definition: creates the original schema using DDL. Storage structure and access methods: chooses file organization and indexes. Schema and physical changes: modifies design as needs grow. Authorization: grants and revokes access rights. Routine maintenance: scheduled backups, security patches, upgrades, free-space checks.

1.6 Basic terminology

Term Meaning Table (relation) Data arranged in rows and columns under a name

Row (tuple, record) One complete entry, for example one student

Column (attribute, field) One property of every row, for example city Schema The structure or design of the database; changes rarely

Instance The data stored at one moment; changes often Metadata Data about data: table names, column types, constraints (kept in the data dictionary)

Query A request to read or change data

🧠 Quick Revision Data is raw; information is data with context. DBMS = database + programs to manage it. Seven file-system problems justify a DBMS. DBA controls schema, storage, security and backups.

2.3 Data independence

D E F I N I T I O N Data independence is the ability to change the schema at one level without changing the schema at the next higher level.

PHYSICAL DATA INDEPENDENCE

Change storage (new index, different file layout) without touching the conceptual schema or programs. Easier to achieve.

LOGICAL DATA INDEPENDENCE

Change the conceptual schema (add a column or table) without rewriting external views or programs. Harder to achieve.

⚠ Common Mistake Mixing up the two. Physical independence is about how data is stored; logical independence is about what data exists. Logical is the harder one because programs depend directly on the logical structure.

2.4 Database languages

DDL (Data Definition Language): defines the schema and constraints. Its output is stored in the data dictionary. DML (Data Manipulation Language): retrieval, insertion, deletion and update of data. The retrieval part is called a query language.

Real systems such as SQL combine both in one language. Chapter 10 splits SQL further into DDL, DML, DQL, DCL and TCL.

Application programs written in a host language (C++, Java, Python) send SQL to the database through an API such as ODBC (Open Database Connectivity, language-neutral, Microsoft-originated) or JDBC (Java Database Connectivity).

2.5 Application architectures: 1, 2 and 3 tier

Two-tier

Client + app logic

SQL over network

Database server

Three-tier

Client (browser/app)

Application server

Database server

business logic

Architecture Description Typical use

1-tier Client, application and database on one machine Local learning setups, small desktop tools 2-tier Client talks to the database server directly through ODBC/JDBC

Small office applications

3-tier Client talks only to an application server, which holds business logic and talks to the database

Web applications

Why 3-tier wins for the web: it scales (add more application servers), protects integrity (one layer enforces business rules) and is more secure (clients cannot reach the database).

🧠 Quick Revision External → Conceptual → Internal is top to bottom. Schema = design; instance = current data. Physical independence is easier than logical. 3-tier = client, application server, database server.

Weaknesses: scaling out across many machines is hard, and very large complex data makes the system heavy.

3.4 Object-oriented and object-relational models

The object-oriented model stores data as objects with attributes and methods, using classes, inheritance and object identity, as in object-oriented programming. It suits complex data such as engineering drawings or multimedia, and avoids converting objects to rows. Its drawbacks are a smaller ecosystem and no single standard query language. Examples: ObjectDB, GemStone.

The object-relational model adds object features (user-defined types, inheritance) on top of relational tables, so it keeps SQL while holding richer data.

3.5 Other families you should recognise

NoSQL databases: non-tabular stores (key-value, document, column family, graph) built for flexible schemas and horizontal scaling. See Chapter 20.

3.6 Comparison of data models

Model Structure Relationships Flexibility Example

Hierarchical Tree 1:N only Low IBM IMS

Network Graph M:N allowed Medium, complex to maintain

IDS, IDMS

Relational Tables Through keys High, standard SQL MySQL, Oracle

Object- oriented

Objects and classes References, inheritance High for complex data

ObjectDB

NoSQL Key-value, document, column, graph

Embedded or application-managed

Very high, schema- free

MongoDB, Cassandra

🎯 Exam Tip "Tree versus graph" is the one-line difference between hierarchical and network models. Draw the small picture above to earn the diagram marks.

🧠 Quick Revision Hierarchical = tree, network = graph, relational = tables. Relational is dominant because of SQL and integrity guarantees. Object-relational = relational + objects.

4

C H A P T E R

The ER Model Drawing the blueprint of a database before building it.

D E F I N I T I O N The Entity-Relationship (ER) model is a high-level data model that describes the real world as a set of entities and the relationships among them. Its graphical form, the ER diagram , is the blueprint of the database.

4.1 Entities and entity sets

Entity: a thing in the real world that can be told apart from every other thing, such as one student or one book. Entity set: all entities of the same type sharing the same attributes, such as the set Book. Strong entity: has its own key and exists independently. Weak entity: has no key of its own and depends on an owner (strong) entity for identification. It needs the owner's key plus its own partial key (discriminator).

Example: a Loan is strong. Its Instalment is weak, because "instalment 3" only means something for a particular loan.

4.2 Attributes and their types

An attribute is a property of an entity. Each attribute has a domain , the set of permitted values.

Type Meaning Example Drawn as

Simple (atomic) Cannot be split further roll_no Single oval Composite Made of sub-parts address = street, city, PIN Oval with child ovals

Single-valued One value per entity date of birth Single oval Multi-valued Several values per entity phone numbers Double oval

Derived Computed from other attributes age from date of birth Dashed oval

Key Uniquely identifies the entity roll_no Underlined text

💡 Remember A NULL value means "not applicable" (a person with no middle name) or "unknown" (salary not yet decided). NULL is not zero and not an empty string.

4.3 Relationships

A relationship is an association among entities ("a member borrows a book"). A relationship set is the set of all such associations. A relationship can carry its own attributes, such as due_date on borrows.

Member

member_id

name

phones

Borrows

M N

due_date

Book

isbn

title

Written by

N

Author

M

Member and Book are in an M:N relationship. The attribute due_date belongs to the relationship, not to either entity.

⚠ Common Mistake

Putting due_date inside Book or Member. It describes one particular borrowing, so it belongs to the relationship.

🧠 Quick Revision

Entity = rectangle, attribute = oval, relationship = diamond. Double oval = multi-valued; dashed oval = derived; underline = key. Cardinality: 1:1, 1:N, N:1, M:N. Participation: total or partial. Weak entity = no key of its own; needs owner's key + discriminator.

5

C H A P T E R

Enhanced ER Model Specialization, generalization, inheritance and aggregation for complex designs.

Basic ER features model most databases. When a design gets complex, the extended features

keep it tidy.

5.1 Specialization (top-down)

D E F I N I T I O N Specialization splits an entity set into sub-entity sets that differ in some way. The original set is the superclass ; the new sets are subclasses. The link is an "is-a" relationship, drawn as a triangle.

Why? Some attributes apply only to a few entities. Example: Person splits into Student (has roll_no ) and Teacher (has salary , subject ). Student-only attributes need not clutter every person.

5.2 Generalization (bottom-up)

The reverse process. The designer notices that several entity sets share attributes and merges the common part into a new superclass. Example: Car , Bus and Truck all have reg_no , colour , owner , so we create Vehicle.

Vehicle

is-a

Car Bus Truck

going down = specialization going up = generalization

SPECIALIZATION

Top-down. One set is refined into several. Shows distinctive features of subsets.

GENERALIZATION

Bottom-up. Several sets are merged into one. Removes repeated attributes.

5.3 Inheritance

Attribute inheritance: a subclass gets all attributes of its superclass. Student inherits name and dob from Person. Participation inheritance: if the superclass takes part in a relationship, so do its subclasses.

6

C H A P T E R

The Relational Model Tables, tuples, attributes and the properties that make a table a relation.

D E F I N I T I O N The relational model organizes data as relations (tables). A relational database is a collection of tables, each with a unique name. Systems built on it are called RDBMS : MySQL, Oracle, PostgreSQL, SQL Server.

6.1 Terminology

Here is a small Student relation we will reuse.

roll_no name city dept_id

101 Asha Noida CS

102 Ravi Delhi EC 103 Meera Noida CS

Term Meaning In the table above Relation The table itself Student

Tuple One row, one record (101, Asha, Noida, CS)

Attribute A column roll_no, name, city, dept_id

Domain Permitted values of an attribute city: set of city names

Relation schema Name + attributes Student(roll_no, name, city, dept_id)

Degree Number of attributes (columns) 4 Cardinality Number of tuples (rows) 3

⚠ Common Mistake Mixing up degree and cardinality. Degree counts columns; cardinality counts rows. (The word "cardinality" also appears in ER diagrams, where it means the mapping ratio such as 1:N.)

6.2 Properties of a relation

Each relation has a distinct name, and each attribute name is unique within it. Every value is atomic : no lists or nested tables inside a cell. Every tuple is unique. There are no duplicate rows. The order of rows and columns does not matter. Values follow the attribute's domain, and the table follows its integrity constraints.

6.3 Why the relational model succeeded

Simple tabular view that anyone can read. Mathematical foundation (relational algebra, Chapter 9) that lets the system optimise queries. Declarative language: say what you want, not how to get it. Integrity enforced by constraints, not by programmers.

🧠 Quick Revision Relation = table, tuple = row, attribute = column. Degree = columns, cardinality = rows. Values are atomic; no duplicate tuples; order irrelevant.

Primary key versus foreign key

Primary key Foreign key

Identifies each row of its own table Links a row to a row of another table Cannot be NULL Can be NULL (unless declared NOT NULL)

Unique values only Duplicates allowed Only one per table Any number per table

Defines the parent side Defines the child (referencing) side

⚠ Common Mistake Saying a candidate key can be any unique column set. It must be minimal. {emp_id, name} is a super key but not a candidate key.

7.2 Integrity constraints

D E F I N I T I O N Integrity constraints are rules the DBMS checks on every insert, update and delete so the database cannot become inconsistent.

Constraint Rule Violation example Domain Each value must be of the declared type and range

marks = 'abc'; age = -

Entity integrity The primary key is never NULL and is unique Inserting a student with roll_no NULL

Referential integrity

A foreign key value must exist in the parent table or be NULL

Student with dept_id 'XX' that is not in Department

SQL column constraints

Constraint Effect NOT NULL The column must always have a value

UNIQUE No two rows share a value; NULL allowed; many per table PRIMARY KEY NOT NULL + UNIQUE; one per table

FOREIGN KEY Value must match a parent key

CHECK Value must satisfy a condition, e.g. marks BETWEEN 0 AND 100 DEFAULT Value used when none is supplied

What happens to child rows when a parent changes?

The foreign key can be told how to react: ON DELETE CASCADE deletes dependent rows too; ON DELETE SET NULL sets the child key to NULL; ON UPDATE CASCADE copies a changed parent key into the children; the default ( RESTRICT ) refuses the change.

🎯 Exam Tip

Three integrity types (domain, entity, referential) are asked directly. Give one violation example for each.

🧠 Quick Revision

Super ⊇ candidate ⊇ primary. PK = unique + not null; FK may repeat or be null. Entity integrity protects the PK; referential integrity protects the FK.