محاضرة 10
Final Review and Practical Training
مراجعة شاملة لجميع مواضيع المنهج وحل تطبيقات عملية استعداداً للاختبار النهائي.
يلا نشوف الملخص
Database Systems: SQL Advanced Commands (Lecture 10)
1. Conditional Logic (The CASE Expression)
The CASE statement goes through conditions and returns a value when the first condition is met (like an If-Then-Else statement).
- Syntax:
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ELSE result END; - Usage in ORDER BY:
- It allows for Conditional Sorting.
- Example: If the
Citycolumn is NULL, sort byCountryinstead.
SELECT * FROM EMPLOYEE ORDER BY ( CASE WHEN City IS NULL THEN Country ELSE City END );
2. Range Filtering (BETWEEN Operator)
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.
- The
BETWEENoperator is inclusive: begin and end values are included. - Syntax:
(This is equivalent toSELECT * FROM Products WHERE Price BETWEEN 3000 AND 7000;Price >= 3000 AND Price <= 7000).
3. Limiting Results (LIMIT Clause)
The LIMIT clause is used to specify the number of records to return. It is very useful on large tables to improve performance.
- Syntax:
(This returns only the top 3 cheapest products).SELECT * FROM Products ORDER BY Price ASC LIMIT 3;
4. Deleting Data (TRUNCATE TABLE)
The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.
- Difference from DROP:
DROP TABLEdeletes the data AND the structure (schema).TRUNCATEkeeps the structure but wipes the data clean. - Difference from DELETE:
TRUNCATEis faster and removes all rows without a WHERE clause. - Syntax:
TRUNCATE TABLE Products;
في نقطة مش واضحة؟ بطبط موجود!
اسأل بطبط عنها