Q.Differentiate between:
Three classic pairs: schema is the blueprint while state is the data currently inside it; a primary key identifies tuples in its own relation while a foreign key points to another relation's primary key; degree counts columns while cardinality counts rows.
a) Database schema vs database state
| Basis | Database schema | Database state |
|---|---|---|
| What it is | The overall design: relation names, attributes, data types, constraints (keys, NOT NULL, CHECK) | The collection of tuples actually stored in the relations at a particular moment |
| When it changes | Rarely — only when the design is altered (CREATE/ALTER TABLE) | Continuously — every INSERT, UPDATE, DELETE produces a new state |
| Defined when | At database design time | At run time, as data flows in |
| Analogy | The printed blank admission form | The pile of filled-in forms today |
Example: STUDENT(RollNo INT PRIMARY KEY, Name VARCHAR(30), Class INT) is schema; the three rows currently stored in STUDENT are its state. The empty database (no data yet) is also a valid state — the empty state.
b) Primary key vs foreign key
| Basis | Primary key | Foreign key |
|---|---|---|
| Purpose | Uniquely identifies each tuple of its own relation | Links a tuple to a tuple of another (referenced) relation |
| Uniqueness | Values must be unique | Values may repeat (many tuples can reference the same master tuple) |
| NULL | Never NULL (entity integrity) | May be NULL, if the relationship is optional |
| How many | Exactly one per relation (possibly composite) | A relation can have several foreign keys |
| Integrity rule enforced | Entity integrity | Referential integrity |
Example:
CREATE TABLE DEPARTMENT (DeptID INT PRIMARY KEY, DeptName VARCHAR(30));
CREATE TABLE EMPLOYEE (EmpID INT PRIMARY KEY, EName VARCHAR(30),
DeptID INT, FOREIGN KEY (DeptID) REFERENCES DEPARTMENT(DeptID));
EmpID identifies employees; DeptID in EMPLOYEE is the foreign key tying each employee to a department, and several employees may share DeptID = 10.
c) Degree vs cardinality of a relation
| Basis | Degree | Cardinality |
|---|---|---|
| Counts | Number of attributes (columns) | Number of tuples (rows) |
| Changes when | The design changes (add/drop a column) | Data changes (insert/delete rows) |
Example — this relation:
| RollNo | Name | Class |
|---|---|---|
| 1 | Asha | 11 |
| 2 | Vikram | 11 |
has degree 3 (RollNo, Name, Class) and cardinality 2 (two tuples).
a) Schema = the time-invariant design of the database (relations, attributes, types, constraints); state = the actual data stored at a given instant, changing with every insert/update/delete.
b) Primary key = the chosen attribute(s) that uniquely and non-NULL-y identify tuples in their own relation (entity integrity); foreign key = attribute(s) referencing another relation's primary key, possibly repeated or NULL (referential integrity).
c) Degree = number of attributes (columns); cardinality = number of tuples (rows). A relation of 3 columns and 2 rows has degree 3, cardinality 2.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.