Database Schema

A database schema is the logical blueprint of a database. It defines how data is organized, including tables, attributes, relationships, and constraints.

1. What is Database Schema?

A database schema represents the structure of a database at a particular level. It defines how data is stored and how different data elements are related.

2. Schema vs Instance

Schema                         Instance
----------------------------   ----------------------------
Logical structure              Actual data
Rarely changes                 Changes frequently
Design-time                    Run-time

3. Types of Database Schema

4. Physical Schema

Physical schema describes how data is actually stored in storage devices.

Disk → Files → Records → Fields

5. Logical Schema

Logical schema describes what data is stored and relationships among data. It is independent of physical storage.

STUDENT (RollNo, Name, CourseID)
COURSE  (CourseID, CourseName)

6. View Schema

View schema defines different views for different users. It provides security and abstraction.

Admin View    → Full access
Teacher View  → Student details only
Student View  → Own record only

7. Schema Diagram

STUDENT ────────┐
  | RollNo (PK) │
  | Name        │
  | CourseID ───┼──────► COURSE
                 |         | CourseID (PK)
                 |         | CourseName

8. Importance of Database Schema

Practice Questions

  1. What is database schema?
  2. Differentiate between schema and instance.
  3. Explain types of database schema.
  4. What is view schema?
  5. Why database schema is important?

Practice Task

Create a logical schema for: ✔ College database ✔ Hospital database ✔ Library management system