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 β Domain) | Age (only allowed Integer β Domain) | Course_ID |
---|---|---|---|
101 | Ravi | 20 | C101 |
102 | Meena | 21 | C102 |
-- Creating the Student table with MySQL datatypes CREATE TABLE Student ( Roll_No INT PRIMARY KEY, -- INT β Numeric values (e.g., 101, 102) Name VARCHAR(50), -- VARCHAR β Variable length string (e.g., 'Ravi') Age INT CHECK (Age >= 18), -- INT β Only whole numbers (e.g., 20) Course_ID CHAR(5), -- CHAR β Fixed length string (e.g., 'C101') DOB DATE, -- DATE β Stored in 'YYYY-MM-DD' format Admission_Date DATETIME, -- DATETIME β 'YYYY-MM-DD HH:MM:SS' Remarks TEXT -- TEXT β Long text storage (not CLOB in MySQL) );
'YYYY-MM-DD'
(e.g., '2025-10-01')'YYYY-MM-DD HH:MM:SS'
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');
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