Schema vs Instance, Data Independence, Degree vs Cardinality, and Database Keys Explained

1. Schema vs Instance — 6 Marks

A schema is the logical structure or design of a database. It describes tables, attributes, relationships and constraints.

Example: Student(Rollno, Name, Branch, Marks)

This structure is the schema.

Instance

An instance is the actual data stored in the database at a particular moment.

Example:

Roll NoNameBranchMarks
101RahulCSE78
102AmitCSE85

This actual data represents an instance.

Difference Between Schema and Instance

SchemaInstance
Structure/design of databaseActual data in database
Changes rarelyChanges frequently
Defined during database designChanges whenever data is inserted, updated or deleted
Example: Student(RollNo, Name, Marks)Example: (101, Rahul, 78)

Conclusion: Schema defines what the database looks like, while instance represents what data is currently stored.

2. Physical vs Logical Data Independence — 6 Marks

Data independence is the ability to change one level of database structure without affecting the higher level.

Physical Data Independence

It means changes in the physical/internal level do not affect the conceptual level.

Examples:

  • Changing file organization
  • Changing indexes
  • Changing storage devices
  • Changing storage techniques

Example: Changing from sequential storage to indexed storage without changing tables or applications.

Logical Data Independence

It means changes in the conceptual/logical level do not affect external views or application programs.

Examples:

  • Adding a new attribute
  • Adding a new table
  • Changing relationships
  • Modifying logical structure

Difference Between Physical and Logical Data Independence

Physical Data IndependenceLogical Data Independence
Deals with physical storageDeals with logical structure
Internal level changesConceptual level changes
Easier to achieveMore difficult to achieve
Example: changing indexesExample: adding an attribute

Conclusion: Both provide flexibility and make database maintenance easier.

3. Degree vs Cardinality — 6 Marks

Degree

The degree of a relation is the number of attributes/columns in a table.

Example:

RollNoNameBranchMarks
101AmitCSE80

There are 4 columns. Degree = 4

Cardinality

The cardinality of a relation is the number of tuples/rows in a table.

If the table contains 50 students: Cardinality = 50

Difference Between Degree and Cardinality

DegreeCardinality
Number of columnsNumber of rows
Also called arityNumber of tuples
Usually changes less frequentlyCan change frequently
Example: 4 attributes → degree 4Example: 50 records → cardinality 50

Easy trick:

  • Degree = Columns
  • Cardinality = Rows

4. Super Key vs Candidate Key vs Primary Key vs Foreign Key — 6 Marks

1. Super Key

A super key is one or more attributes that can uniquely identify a tuple.

Example: STUDENT(RollNo, Name, Email)

Possible super keys:

  • RollNo
  • Email
  • RollNo + Name
  • RollNo + Email

2. Candidate Key

A candidate key is a minimal super key. It uniquely identifies a record and contains no unnecessary attribute.

Example: RollNo and Email. Both can uniquely identify a student, so they are candidate keys.

3. Primary Key

A primary key is the candidate key selected to uniquely identify records.

Example: RollNo → Primary Key

A primary key cannot contain NULL values and must be unique.

4. Foreign Key

A foreign key is an attribute in one table that refers to the primary key of another table.

Example:

STUDENT

RollNoNameDeptID
101AmitD01

DEPARTMENT

DeptIDDeptName
D01CSE

Here, DeptID in STUDENT is a Foreign Key.

Relationship Between Keys

Super Key → Candidate Key → Primary Key

A candidate key is a minimal super key, and one candidate key is selected as the primary key.