text [MConverter.eu] (1)
text [MConverter.eu] (1)
of your course material, enriched with additional SQL knowledge, covering everything
systematically.
# Oracle SQL Notes
## 1. Introduction to Databases
---
## 2. SQL Basics
---
## 3. Data Types
---
## 4. Constraints
| **Constraint** | **Purpose**
| **Example** |
|-------------------|-------------------------------------------------
-----|----------------------------------------|
| `PRIMARY KEY` | Uniquely identifies rows.
| `id INT PRIMARY KEY` |
| `FOREIGN KEY` | Enforces referential integrity.
| `FOREIGN KEY (dept_id) REFERENCES departments(dept_id)` |
| `CHECK` | Limits column values.
| `CHECK (age >= 18)` |
| `NOT NULL` | Prevents NULL values.
| `name VARCHAR2(50) NOT NULL` |
---
### **Commands**
- **`CREATE TABLE`**: Define a new table.
```sql
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR2(50),
age INT
);
7. Queries (DQL)
Simple SELECT
• Retrieve all columns:
SELECT * FROM students;
• Descending order:
SELECT name, age FROM students ORDER BY age DESC;
8. Functions
Single-Row Functions
• Numeric: ROUND, CEIL, FLOOR.
• Character: UPPER, LOWER, LENGTH.
• Date: SYSDATE, ADD_MONTHS.
• Conversion: TO_CHAR, TO_DATE.
Aggregate Functions
• COUNT: Count rows.
SELECT COUNT(*) FROM students;
9. Joins
Types of Joins
Type Description Example
INNER JOIN Rows matching both SELECT * FROM A
tables. JOIN B ON A.id =
B.id;
LEFT JOIN All rows from left table, SELECT * FROM A
matching rows from LEFT JOIN B ON
right table. A.id = B.id;
RIGHT JOIN All rows from right SELECT * FROM A
table, matching rows RIGHT JOIN B ON
from left table. A.id = B.id;
FULL OUTER JOIN All matching and non- SELECT * FROM A
matching rows from FULL OUTER JOIN B
both tables. ON A.id = B.id;
SELF JOIN Joins a table with itself. SELECT a.col,
b.col FROM A a, A
b WHERE a.id >
b.id;
DML Practice
• Insert rows into a table.
• Update records to test CHECK constraints.
• Delete records based on a condition.
Query Practice
• Retrieve employees with salary > $50,000.
• Aggregate queries for average salaries by department.
• Use joins to find employees and their managers.
This Markdown file comprehensively combines all topics, commands, and examples
covered in your course material. If you’d like, I can refine this or export it to a different
format such as PDF or HTML.