A Functional Dependency (FD) shows a relationship between two attributes where one attribute determines another.
It is written as:
Example:
If we know the Student ID, we can find the student's name.
| Type | Meaning | Example |
|---|---|---|
| Trivial FD | Right-side attribute is already part of the left side | {A, B} → A |
| Non-Trivial FD | Right-side attribute is not part of the left side | A → B |
Trivial = Already Included
Non-Trivial = New Information
SQL Constraints are rules applied to table columns to maintain correct and valid data.
Four types are:
FOREIGN KEY → Connects two tables
NOT NULL → Does not allow empty values
UNIQUE → Does not allow duplicate values
P-F-N-U
> Primary → Foreign → Not Null → Unique
Relational Algebra is a procedural query language used to retrieve and manipulate data from relational tables.
Four fundamental operations are:
- SELECT (σ) → Selects required rows
- PROJECT (π) → Selects required columns
- UNION (∪) → Combines rows from two compatible tables
- SET DIFFERENCE (−) → Finds rows present in one table but not another
S-P-U-D
> Select → Project → Union → Difference
| Function | Purpose |
|---|---|
| UPPER() | Converts text to uppercase |
| LOWER() | Converts text to lowercase |
| LENGTH() | Finds the length of a string |
| CONCAT() | Joins two or more strings |
Example:
UPPER('arun')
Result: ARUN
Upper → Lower → Length → Join
ACID properties ensure that database transactions are performed safely and reliably.
| Property | Simple Meaning |
|---|---|
| Atomicity | All operations happen or none happen |
| Consistency | Database remains correct |
| Isolation | Transactions do not interfere with each other |
| Durability | Committed data is permanently saved |
A-C-I-D
> All or Nothing
Correct
Independent
Don't Lose
A JOIN is used to combine data from two or more tables using a related column.
Four types:
- INNER JOIN → Returns matching rows
- LEFT JOIN → All rows from left table + matching rows from right
- RIGHT JOIN → All rows from right table + matching rows from left
- FULL OUTER JOIN → All rows from both tables
Inner = Matching
Left = Everything Left
Right = Everything Right
Full = Everything Both
| Constraint | Purpose |
|---|---|
| NOT NULL | Ensures a column cannot have an empty/NULL value |
| UNIQUE | Ensures values are not duplicated |
| CHECK | Ensures values satisfy a specified condition |
Example:
Age INT CHECK (Age >= 18)
This allows only age 18 or above.
> NOT NULL → Must have value
> UNIQUE → No duplicate
> CHECK → Follow the rule
ISAM (Indexed Sequential Access Method):
Stores records in a sorted/indexed order.
Good for sequential and direct access.
B-Tree:
A balanced tree structure used for fast searching.
Maintains data in sorted order.
ISAM → Sorted Index
B-Tree → Balanced Tree
Aggregate functions perform calculations on multiple rows and return one result.
Examples:
SUM() → Calculates total
AVG() → Calculates average
MAX() → Finds highest value
MIN() is another commonly used aggregate function.
C-S-A-M
> Count → Sum → Average → Maximum
A Correlated Subquery is a subquery that depends on the outer query to get its values.
Key Characteristic:
It is generally executed once for each row processed by the outer query.
Simple Idea:
Outer Query
↓
Subquery needs outer query's value
↓
Result
> Correlated = Connected
The inner query is connected to the outer query.
Four principles/rules of Codd's relational model are:
- Information Rule → Data is represented as values in tables.
- Guaranteed Access Rule → Every data value can be accessed using table name, primary key, and column name.
- Systematic Treatment of NULL → Missing or unknown values are handled systematically.
- Dynamic Online Catalog → Database structure/metadata is stored in tables and can be queried.
I-G-N-C
> Information → Guaranteed Access → NULL → Catalog
| Function | Purpose |
|---|---|
| CURRENT_DATE | Returns the current date |
| CURRENT_TIME | Returns the current time |
| CURRENT_TIMESTAMP | Returns current date and time |
| EXTRACT() | Extracts a part such as year, month, or day |
> Date → Time → Both → Extract
Referential Integrity ensures that a Foreign Key value must match an existing Primary Key value in the referenced table, or be NULL where permitted.
Example:
If:
Department_ID = 10
Then a student can have:
But not:
if department 99 does not exist.
> Foreign Key must point to a valid record.
Referential Integrity = No Broken Links 🔗
| COUNT() | SUM() |
|---|---|
| Counts the number of rows/values | Calculates the total of numeric values |
| Example: COUNT(Mark) | Example: SUM(Mark) |
Example:
Suppose marks are:
COUNT(Mark)
Result: 3
SUM(Mark)
Result: 240
> COUNT = How many?
> SUM = How much total?
A Subquery is a query written inside another SQL query.
Example:
SELECT Name FROM Student WHERE Mark > (SELECT AVG(Mark) FROM Student);
The inner query finds the average mark, and the outer query finds students above that average.
Applications:
Filtering records
Finding calculated results
Checking conditions
> Subquery = Query inside Query
1. Primary Index
An index created using the primary key or ordering key of a table.
2. Secondary Index
An index created on a non-ordering attribute to provide faster searching.
3. Multilevel Index
An index where another index is created on top of an existing index, forming multiple levels.
Simple Diagram:
Level 2 Index
↓
Level 1 Index
↓
Data
Primary → Main key
Secondary → Other field
Multilevel → Index on index
| Function | Purpose |
|---|---|
| ABS() | Returns absolute value |
| ROUND() | Rounds a number |
| CEIL() / CEILING() | Rounds up to the next integer |
| FLOOR() | Rounds down to the previous integer |
Example:
ROUND(25.67)
Result:
> ABS → ROUND → CEIL → FLOOR
Think:
Value → Round → Up → Down
| Trivial FD | Non-Trivial FD |
|---|---|
| Right-side attributes are already included in left side | Right-side attribute is not included in left side |
| {A, B} → A | A → B |
| Gives no new information | Gives new information |
Suppose:
{Student_ID, Name} → Name
Name is already on the left side.
✅ Trivial
But:
Student_ID → Name
Name is not on the left side.
✅ Non-Trivial
> TRIVIAL = Already there
> NON-TRIVIAL = New information
0 Comments