Chapter 4- Structured Query Language (SQL)-PARTA notes
Chapter 4- Structured Query Language (SQL)-PARTA notes
Query:
● Purpose: The HAVING clause is used to filter groups after the GROUP BY clause has been applied.
● It is similar to the WHERE clause, but WHERE is used to filter rows before grouping, while HAVING is used to filter groups after
aggregation.
● Usage: HAVING is often used in conjunction with aggregate functions.
FROM sales
GROUP BY category
Subqueries:
Example
NOT IN Operator
Not BETWEEN Operator
Like Operator
SQL NULL Values
IS-NULL Operator
IS NOT NULL operator
INTEGRITY CONSTRAINTS
1. Domain Constraint
2. Entity integrity contraint
3. Referential integrity Constraint
Syntax Referential Integrity
CREATE TABLE Department ( -- Inserting into Department table
INSERT INTO Department (DeptID, DeptName)
DeptID INT PRIMARY KEY, VALUES (1, 'HR'), (2, 'IT');
DeptName VARCHAR(100)
-- Inserting into Employee table with valid DeptID
); INSERT INTO Employee (EmpID, EmpName, DeptID)
VALUES (101, 'John Doe', 1),
(102, 'Jane Smith', 2);
CREATE TABLE Employee (
Example:
Let's say we have a table employees with columns employee_id, name, department, and salary.
A complex view is created from multiple tables or includes complex SQL operations such as JOINs, GROUP BY, HAVING, and
subqueries.
Example:
AS
FROM employees e
A materialized view stores the result of a query physically on the disk. It is refreshed periodically and provides faster access to query
results compared to regular views.
Example:
AS
FROM employees
GROUP BY department;