The Relational Model is a way to store and manage data in tabular form. It was introduced by E.F. Codd in 1970.
Roll_No | Name(only allowed String this is one type of domain) | Age(only allowed Integer this is one type of domain) | Course_ID |
---|---|---|---|
101 | Ravi | 20 | C101 |
102 | Meena | 21 | C102 |
Uniquely identifies each row in a table.
β οΈ Cannot be NULL or duplicate.
Example: Roll_No in Student table
All possible unique keys.
Example: Roll_No, Email
Candidate keys that are NOT chosen as Primary Key.
Example: Email (when Roll_No is Primary)
Any set of attributes that uniquely identifies rows.
Example: {Roll_No, Name}
Links to a Primary Key from another table.
Example: Student.Course_ID β Course.ID
Combination of 2+ columns used as a Primary Key.
Example: {Student_ID, Subject_ID} in Marks table
CREATE TABLE Course (
Course_ID VARCHAR(10) PRIMARY KEY
);
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Course_ID VARCHAR(10),
FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
INSERT INTO Course (Course_ID) VALUES ('C999');
INSERT INTO Student (Student_ID, Course_ID) VALUES (101, 'C999');
Action | Effect on Child |
---|---|
ON INSERT (invalid FK) | Insert fails if referenced key is missing in parent |
ON DELETE CASCADE | Deletes matching child rows |
ON DELETE SET NULL | Sets foreign key to NULL |
ON DELETE NO ACTION | Prevents deletion if child exists |
ON UPDATE CASCADE | Updates foreign key in child |
ON UPDATE NO ACTION | Prevents update if child exists |
Constraint Type | Description | Example |
---|---|---|
Domain | Limits value type | Age should be 18β25 |
Entity Integrity | Primary Key can't be NULL | Roll_No always required |
Referential Integrity | Foreign Key must match valid Primary Key | Course_ID must exist in Course table |
Unique | No duplicates allowed | |
Not Null | Must have value | Name, Age |
It's a mathematical way to express queries on tables.
Selects all students with age greater than 21
Shows only Name and Age columns
β Both tables must have same attributes
Students who are not alumni
Every student paired with every course
Combines related records from two tables
Roll_No | Name | Age | Course_ID |
---|---|---|---|
101 | Ravi | 20 | C101 |
102 | Meena | 21 | C102 |
Course_ID | Course_Name |
---|---|
C101 | DBMS |
C102 | OS |
Tip No. | Tip |
---|---|
1 | Always explain with Student/Course/Employee example |
2 | Emphasize why keys are important: uniqueness and relation |
3 | Prepare 2β3 relational algebra queries |
4 | Be able to explain JOIN vs PRODUCT |
5 | Practice how constraints keep data clean |
6 | Draw mini tables during interviews to explain answers |
Answer:
Answer: Yes, it can be NULL if the relation is optional.
Answer: 3 Γ 4 = 12 rows
Topic | Shortcut |
---|---|
Table | Relation |
Row | Tuple |
Column | Attribute |
Unique column | Primary Key |
Rule on column | Constraint |
Filter rows | Select (Ο) |
Select columns | Project (Ο) |
Combine tables | Join (β¨) |
Merge rows | Union (βͺ) |
Cross-pairing | Cartesian (Γ) |