SQL
�Introduction to SQL
How SQL Works?
Syntax: SELECT * FROM students WHERE grade = ‘A’;
History of SQL
🔹 1970 – The Birth of the Relational Model�🔹 1973 – SQL is Developed at IBM�🔹 1976 – SEQUEL becomes SQL�🔹 1980s – SQL Becomes a Standard�🔹 1980s–1990s – SQL Grows in Popularity�🔹 2000s–Present – Continuous Improvement��
🔹 1.Managing Databases: SQL is used to create, modify, and manage databases. You can define tables, insert data, update records, and delete unwanted data.�🔹 2. Data Retrieval: You can query large datasets and retrieve specific data using SQL. � Example: Get a list of all customers who made a purchase this month.�🔹 3. Web Development: Websites use SQL to store and fetch user data.�Example: Login systems, product search, comment sections.�🔹 4. Mobile Apps: Apps like Instagram, Facebook, and Uber use SQL in the background to manage user profiles, messages, transactions, etc.�🔹 5. Data Analysis: Data analysts use SQL to analyze large datasets, generate reports, and find insights. Tools like Power BI, Tableau often integrate with SQL databases.�🔹 6. Business Intelligence (BI): SQL helps businesses make data-driven decisions by accessing and visualizing key business metrics.��
��🔹 7. Finance & Banking: Used for handling transactions, customer accounts, ATM records, fraud detection, etc.�🔹 8. Healthcare Systems: Hospitals use SQL to store patient records, appointment data, billing information.�🔹 9. E-commerce Platforms: Stores use SQL to manage product inventories, orders, customer details, and reviews.�🔹 10. Education Systems: Schools and universities store student data, attendance, results, course details using SQL databases.�
🔹 6. Integrates with Other Tools: SQL works well with data tools like Power BI, Tableau, Excel, Python, and R. This makes it perfect for reporting and advanced analysis.�🔹 7. Supports Decision Making: Businesses use SQL to track performance, customer trends, sales, etc. This helps in making data-driven decisions.�🔹 8. Automation and Security: SQL allows automation of repetitive tasks. It also includes permissions and user controls to secure data access.�🔹 9. Career Growth: SQL is in high demand. Knowing SQL opens opportunities in roles like: � Data Analyst� Database Administrator� Software Developer� Business Analyst
DBMS VS RDBMS
Feature | DBMS (Database Management System) | RDBMS (Relational Database Management System) |
Definition | A system used to store and manage data in any format (e.g., files, hierarchies, etc.) without enforcing relational rules. | A system that manages data stored in a structured format with tables, rows, and columns, enforcing relational rules (using primary and foreign keys). |
Data Structure | Non-relational data storage (e.g., files, hierarchical format). | Relational data storage in tables with rows and columns. |
Data Relationships | Does not enforce relationships between data elements. | Enforces relationships between tables using primary and foreign keys. |
ACID Properties | May not support full ACID (Atomicity, Consistency, Isolation, Durability) properties. | Supports full ACID properties to ensure data integrity and transaction consistency. |
Query Language | May or may not use SQL for querying and manipulating data. | Uses SQL (Structured Query Language) for querying and manipulating data. |
Examples | Examples include XML databases, file systems, and hierarchical databases. | Examples include MySQL, PostgreSQL, Oracle, SQL Server, etc. |
Scalability | Limited scalability, more suited for small-scale applications. | Highly scalable, designed for large-scale applications with complex data relationships. |
Use Case | Best suited for small-scale applications where data relationships are minimal. | Used in large-scale applications where complex relationships, transactions, and data integrity are required. |
Security | Provides limited security mechanisms. | Offers better security mechanisms with user roles, permissions, and encryption. |
Normalization | Not necessarily follows normalization processes. | Follows normalization techniques to minimize redundancy and improve data integrity. |
Backup and Recovery | Limited built-in backup and recovery options. | Provides better backup and recovery mechanisms. |
Popular RDBMS tools: MySQL, PostgreSQL, SQL Server, Oracle
1. MySQL
2. PostgreSQL
3. SQL Server
4. Oracle Database
Summary Table
Tool | Type | Known For | Ideal For |
MySQL | Open-source | Simplicity, speed | Web applications |
PostgreSQL | Open-source | Extensibility, SQL compliance | Research, analytics, custom solutions |
SQL Server | Commercial | Integration with Microsoft ecosystem | Enterprise business software |
Oracle | Commercial | High-end features, performance | Large enterprises, financial systems |
BASICS OF SQL
Understanding tables, rows, columns
Table:
Example: A "Students" table.
Row (Record):
Example: One student's details in a row — like Name, Age, Grade.
Column (Field):
Example: "Name", "Age", "Grade" are columns in the "Students" table.
Creating a Database
Syntax: CREATE DATABASE database_name;
Example: CREATE DATABASE SchoolDB;
Using a Database
Syntax: USE database_name;
Example: USE SchoolDB;
Creating a table
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
…………
);
Example:
CREATE TABLE Students (
StudentID INT,
Name VARCHAR(50),
Age INT,
Grade VARCHAR(5)
);
Inserting Data into tables
Syntax: INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Example: INSERT INTO Students (StudentID, Name, Age, Grade)
VALUES (1, 'Ravi', 15, 'A');
Basic SELECT Statement
Syntax: SELECT column1, column2 FROM table_name;
SELECT * FROM table_name;
Example: SELECT * FROM Students;
SELECT specific columns
Syntax: SELECT column1, column2 FROM table_name;
Example: SELECT Name, Age FROM Students;
SELECT with DISTINCT
The DISTINCT keyword is used to remove duplicates values and return only unique values in query
Syntax: SELECT DISTINCT column1, column2 FROM table_name;
Example: SELECT DISTINCT Grade FROM Students;�
StudentID | Name | Grade |
1 | Ravi | A |
2 | Sita | B |
3 | John | A |
4 | Meena | C |
5 | Rahul | B |
Grade |
A |
B |
C |
DATA TYPES IN SQL
Common data types: INT, VARCHAR, TEXT, DATE, FLOAT, BOOLEAN��������Example:�CREATE TABLE Students (� StudentID INT,� Name VARCHAR(50),� Bio TEXT,� BirthDate DATE,� Marks FLOAT,� IsPassed BOOLEAN�);�����
Data Type | Meaning | Example Values |
INT | Integer (whole numbers) | 10, 0, -5 |
VARCHAR | Variable-length string (text) | 'Ravi', 'apple' |
TEXT | Long text | 'This is a long message' |
DATE | Date value | '2025-05-02' |
FLOAT | Decimal number (floating point) | 99.5, 3.14, -0.25 |
BOOLEAN | True or False (Yes/No) | TRUE, FALSE (1, 0) |
Choosing correct data types
CREATE TABLE Students (� StudentID INT,� Name VARCHAR(50),� MiddleName VARCHAR(50) NULL�);�
NOT NULL: It means that a column must have a value. You cannot leave it empty.
Usage: If you define a column as NOT NULL every row in the table must have a value for that column.
Example:
CREATE TABLE Students (
StudentID INT NOT NULL,
Name VARCHAR(50) NOT NULL,
MiddleName VARCHAR(50) NULL
);
CONSTRAINTS IN SQL
PRIMARY KEY
Example:�CREATE TABLE Students (� StudentID INT PRIMARY KEY,� Name VARCHAR(50),� Age INT�);� Here StudentID is the primary key;� Each student must have a unique and non-null ID.�
Rule | Meaning |
Must be unique | No two rows can have the same primary key value |
Cannot be NULL | Every row must have a value in the primary key |
Only one primary key | A table can have only one primary key |
Can be single or multiple columns | It can be one or more columns combined (composite key) |
Composite Primary Key�
CREATE TABLE Enrollments (
StudentID INT,
CourseID INT,
EnrollmentDate DATE,
PRIMARY KEY (StudentID, CourseID)
);
�
FOREIGN KEY
Example :
Students Table
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50)
);
Enrollment Table
CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseName VARCHAR(50),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);
�UNQUIE KEY
CREATE TABLE Employees (
EmpID INT PRIMARY KEY,
Email VARCHAR(100) UNIQUE,
PhoneNumber VARCHAR(15) UNIQUE,
Name VARCHAR(50)
);
Duplicate Values�INSERT INTO Employees (EmpID, Email, PhoneNumber, Name)
VALUES (1, 'john@example.com', '1234567890', 'John’);
INSERT INTO Employees (EmpID, Email, PhoneNumber, Name)
VALUES (2, 'john@example.com', '9876543210', 'Mike');
NOT NULL
CREATE TABLE Students (� StudentID INT PRIMARY KEY,� Name VARCHAR(100) NOT NULL,� Age INT NOT NULL�);�
Invalid Insert Example:
-- This will cause an error because Name is NOT NULL
INSERT INTO Students (StudentID, Name, Age)
VALUES (1, NULL, 20);
DEFAULT
CREATE TABLE Employees (� EmpID INT PRIMARY KEY,� Name VARCHAR(100) NOT NULL,� Country VARCHAR(50) DEFAULT 'India'�);�
INSERT INTO Employees (EmpID, Name)
VALUES (1, 'Ravi');
CHECK
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT CHECK (Age >= 18)
);
AUTO_INCREMENT(MySQL)
Key Features:
RETRIEVING DATA
SELECT with WHERE Clause
SELECT column1, column2, ...
FROM table_name
WHERE condition;
ID | Name | Department | Salary |
1 | Ravi | HR | 30000 |
2 | Sneha | IT | 50000 |
3 | Akash | HR | 25000 |
4 | Priya | IT | 60000 |
SELECT * FROM Employees
WHERE Department = 'HR’;
SELECT Name, Salary
FROM Employees
WHERE Salary > 30000;
ID | Name | Department |
1 | Ravi | HR |
3 | Akash | HR |
Name | Salary |
Sneha | 50000 |
Priya | 60000 |
Comparison operators�Comparison operators are used in SQL to compare values in the WHERE clause.
Example: Employees Table
Operator | Meaning |
= | Equal to |
!= or <> | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
ID | Name | Department | Salary |
1 | Ravi | HR | 30000 |
2 | Sneha | IT | 50000 |
3 | Akash | HR | 25000 |
4 | Priya | IT | 60000 |
SELECT * FROM Employees WHERE Salary > 40000;
4. < (Less than): checks if the left value is less than right value
SELECT * FROM Employees WHERE Salary < 30000;
5. >= (Greater Than or Equal To): checks if the left value is greater than or equal to right value.
SELECT * FROM Employees WHERE Salary >= 50000;
6. <= (Less Than or Equal To): checks if the left value is less than or equal to right value.
SELECT * FROM Employees WHERE Salary <= 25000;
SELECT * FROM Employees WHERE Department = 'IT’;
2. != or < >(Not Equal To):check if two values not equal.
SELECT * FROM Employees WHERE Department != 'HR’;
3.>(Greater than): checks if the left value is greater than right value
Logical Operators in SQL (AND, OR, NOT) :Logical operators are used in SQL to combine multiple conditions in the WHERE clause.
1. AND: Returns rows only when both conditions are true.
SELECT * FROM Employees
WHERE Department = 'IT' AND Salary > 40000;
2. OR: Returns rows when either condition is true (or both).
SELECT * FROM Employees
WHERE Department = 'HR' OR Salary < 30000;
3. NOT: Reverses the result of a condition — returns rows where the condition is false.
SELECT * FROM Employees
WHERE NOT Department = 'IT';
BETWEEN, IN, NOT IN:��
1. BETWEEN
Syntax: SELECT * FROM Employees WHERE Salary BETWEEN 30000 AND 50000;
ID | Name | Department | Salary |
1 | Ravi | HR | 30000 |
2 | Sneha | IT | 50000 |
3 | Akash | Sales | 25000 |
4 | Priya | Finance | 60000 |
�
2. IN
Syntax: SELECT * FROM Employees WHERE Department IN ('HR', 'IT');
3. NOT IN
Syntax: SELECT * FROM Employees WHERE Department NOT IN ('HR', 'Sales');
LIKE, NOT LIKE
Syntax: SELECT * FROM Employees WHERE Name LIKE 'S%’;
Pattern | Matches |
'A%' | Starts with A (Amit, Anu) |
'%a' | Ends with a (Sneha, Priya) |
'%e%' | Contains "e" anywhere |
'__vi' | Any 2 characters, then "vi" |
2. NOT LIKE� Used to exclude results that match a pattern.�
Syntax: SELECT * FROM Employees WHERE Name NOT LIKE '%a';
ID | Name | Department | Salary |
1 | Ravi | HR | 30000 |
2 | Sneha | IT | 50000 |
3 | Akash | Sales | 25000 |
4 | Priya | Finance | 60000 |
1. IS NULL�Used to find rows where a column has no value (i.e., it is NULL)�Null means unknown or missing data, not zero or blank.�
Syntax: SELECT * FROM Employees WHERE Department IS NULL;
2. IS NOT NULL
Syntax: SELECT * FROM Employees WHERE Department IS NOT NULL;
ID | Name | Department | Salary |
1 | Ravi | HR | 30000 |
2 | Sneha | NULL | 50000 |
3 | Priya | IT | NULL |
Sorting and Limiting Results
ORDER BY: It is used to sort the result of a query based on one or more columns.���
Syntax: SELECT * FROM table_name
ORDER BY column_name ASC; -- or DESC
Syntax: SELECT * FROM Employees ORDER BY Salary ASC;
Syntax: SELECT * FROM Employees ORDER BY Name DESC;
ID | Name | Salary |
1 | Ravi | 30000 |
2 | Sneha | 50000 |
3 | Akash | 25000 |
LIMIT and OFFSET�
LIMIT/TOP:
Syntax: SELECT * FROM Employees LIMIT 5;
O/P: Ravi Sneha Akash Priya Arun
ID | Name | Salary |
1 | Ravi | 30000 |
2 | Sneha | 50000 |
3 | Akash | 25000 |
4 | Priya | 60000 |
5 | Arun | 32000 |
6 | Nikhil | 45000 |
2.OFFSET �
Syntax: SELECT * FROM table_name
LIMIT number_of_rows OFFSET number_of_rows_to_skip;
Example: SELECT * FROM Employees LIMIT 3 OFFSET 2;
FETCH FIRST (PostgreSQL/SQL Server)
FETCH FIRST & FETCH NEXT: Used to get a specific number of rows from a query result.
Syntax: SELECT * FROM table_name
ORDER BY column_name
OFFSET n ROWS FETCH NEXT m ROWS ONLY;
ID | Name | Department |
1 | Ravi | HR |
2 | Sneha | Finance |
3 | Akash | IT |
4 | Priya | Marketing |
5 | Nikhil | HR |
6 | Anu | IT |
7 | Kiran | Finance |
8 | Meena | Marketing |
9 | Vamsi | HR |
10 | Neha | IT |
Example:�SELECT * FROM Employees�ORDER BY ID�OFFSET 4 ROWS FETCH NEXT 5 ROWS ONLY;�
Syntax: SELECT * FROM Employees
ORDER BY ID
OFFSET 5 ROWS FETCH NEXT 3 ROWS ONLY;
OUTPUT
ID | Name | Department |
6 | Anu | IT |
7 | Kiran | Finance |
8 | Meena | Marketing |
FETCH FIRST
Syntax: SELECT * FROM Employees
ORDER BY ID
FETCH FIRST 4 ROWS ONLY;
ID | Name | Department |
1 | Ravi | HR |
2 | Sneha | FINANCE |
3 | Akash | IT |
4 | Priya | MARKETING |
SQL Functions
Aggregate Functions COUNT(), SUM(), AVG(), MIN(), MAX():
Syntax: SELECT COUNT(*) FROM Employees;
Syntax: SELECT SUM(Marks) FROM Employees;
Syntax: SELECT AVG(Marks) FROM Employees;
Syntax: SELECT MIN(Marks) FROM employees;
Syntax: SELECT MAX(Marks) FROM Employees;
String Functions UPPER(), LOWER(), LENGTH(), CONCAT(), SUBSTRING()
Syntax: SELECT UPPER('hello world’);
Output: HELLO WORLD
Syntax: SELECT LOWER('HELLO WORLD’);
Output: hello world
Syntax: SELECT LENGTH('SQL Functions’);
Output: 13
Syntax: SELECT CONCAT('Hello', ' ', 'World’);
Output: Hello World
Syntax: SELECT SUBSTR('Database', 1, 4);
Output: Data
Date & Time Functions NOW(), CURDATE(), DATE_ADD(), DATEDIFF()
Syntax: SELECT NOW();
Syntax: SELECT CURRDATE();
Syntax: SELECT DATE_ADD('2025-05-07', INTERVAL 5 DAY);
Syntax: SELECT DATEDIFF('2025-05-10', '2025-05-01');
Conversion Functions
Syntax: CAST(expression AS target_data_type)
Syntax: CONVERT(target_data_type, expression, [style])
GROUP BY and HAVING
GROUP BY for aggregation:
Syntax: SELECT column1, AGGREGATE_FUNCTION(column2)
FROM table_name
GROUP BY column1;
Example:�
SaleID | SalesPerson | Region | Amount |
1 | Alice | North | 500 |
2 | Bob | South | 300 |
3 | Alice | North | 200 |
4 | Alice | East | 450 |
5 | Bob | South | 150 |
6 | Charlie | North | 400 |
HAVING CLAUSE
Syntax: SELECT column1, AGG_FUNC(column2)
FROM table
GROUP BY column1
HAVING condition_on_aggregate;
Filtering groups using HAVING:
Syntax: SELECT column1, AGG_FUNC(column2)
FROM table_name
GROUP BY column1
HAVING AGG_FUNC(column2) condition;
GROUP BY with multiple columns:
Syntax: SELECT column1, column2, AGG_FUNC(column3)
FROM table_name
GROUP BY column1, column2;
JOINS
JOIN:A JOIN clause is used to combine rows from two or more tables based on a related column between them, usually a foreign key.��EMPLOYEE TABLE�
order_id | customer_id | Item |
101 | 1 | Laptop |
102 | 2 | Mobile |
103 | 4 | Tablet |
customer_id | name |
1 | Alice |
2 | Bob |
3 | Charlie |
1. INNER JOIN: It returns only the rows that have matching values in both tables.�Syntax: SELECT columns� FROM table1� INNER JOIN table2� ON table1.common_column = table2.common_column;�
2. LEFT JOIN (LEFT OUTER JOIN): It returns all rows from the left table and matching rows from the right table. If there’s no match, NULL is returned for right table columns.
Syntax: SELECT columns
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;
3. RIGHT JOIN (RIGHT OUTER JOIN): It returns all rows from the right table and matching rows from the left table. If there’s no match, NULL is returned for left table columns.�Syntax: SELECT columns� FROM table1� RIGHT JOIN table2� ON table1.common_column = table2.common_column;�
4. FULL OUTER JOIN: It returns all rows from both tables. Rows without a match in one of the tables will have NULL values.
Syntax: SELECT columns
FROM table1
FULL OUTER JOIN table2
ON table1.common_column = table2.common_column;
5. CROSS JOIN: It returns all combinations of rows from both tables (Cartesian Product).�Syntax: SELECT *� FROM table1� CROSS JOIN table2;�
6. SELF JOIN: A SELF JOIN s a join of a table with itself. You need to use aliases.
Syntax: SELECT A.column, B.column
FROM table A
JOIN table B
ON A.column = B.related_column;
SUB QUERIES
SUB QUERIES WITH SELECT
SELECT
column1,
(SELECT expression FROM table2 WHERE condition) AS alias_name
FROM table1;
SUB QUERIES IN WHERE CLAUSE
Types of WHERE subqueries:
CORRELATED SUB QUERIES
SYNTAX:
SELECT column1, column2
FROM table1 t1
WHERE columnX = (
SELECT columnY FROM table2 t2
WHERE t2.related_column = t1.related_column
);
EXISTS:� It is used to check whether a subquery returns any rows.�
SYNTAX:
SELECT column1, column2
FROM table1 t1
WHERE EXISTS (
SELECT 1 FROM table2 t2
WHERE t1.id = t2.id
);
NOT EXISTS
SYNTAX:
SELECT Name, DeptID
FROM Employee e
WHERE NOT EXISTS (
SELECT 1 FROM Department d
WHERE d.DeptID = e.DeptID
);
SUB QUERIES IN FROM CLAUSE
SYNTAX:
SELECT columns
FROM (
SELECT ... FROM table WHERE ...
) AS alias_name
WHERE condition_on_derived_table;
SET OPERATIONS
UNION:
Syntax:
SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, ...
FROM table2;
UNION ALL:
SYNTAX:
SELECT column1, column2 FROM table1
UNION ALL
SELECT column1, column2 FROM table2;
EXCEPT/MINUS:
SYNTAX:
SELECT column1, column2 FROM table1
EXCEPT
SELECT column1, column2 FROM table2;
INTERSECT:
SYNTAX:
SELECT column1, column2 FROM table1
INTERSECT
SELECT column1, column2 FROM table2;
MODIFYING DATA
UPDATE Statement
SYNTAX:
UPDATE table_name
SET column1 = value1, column2 = value2;
SYNTAX:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE
SYNTAX:
DELETE FROM table_name
WHERE condition;
DELETE Statement with CONDITION:
SYNTAX:
DELETE FROM table_name
WHERE condition;
TRUNCATE VS DELETE
DELETE�Statement is used to remove rows from a table.
REPLACE AND UPSERT
INDEXES
What is an Index?
Creating an index:
Syntax: CREATE [UNIQUE] INDEX index_name
ON table_name (column1, column2, ...);
VIEWS
VIEW: �A view is a virtual table based on the result of a SQL query. It does not store data physically, but it acts like a table and can be used in SELECT, JOIN, etc.
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
TRANSACTIONS
Definition:� A transaction is a set of one or more SQL statements that are executed as a single unit of work.�All the operations in a transaction must complete successfully,�or else none of them should take effect.�This ensures data accuracy, consistency, and integrity.�
COMMIT :
SYNTAX: COMMIT;
ROLLBACK: �It is a transaction control command used to undo all the changes made in the current transaction.�It is used when something goes wrong (like an error or failed condition).
SYNTAX:
BEGIN TRANSACTION;
-- SQL statements here...
SAVE POINT:� It is used to set a temporary marker within a transaction.�You can ROLLBACK to that savepoint instead of rolling back the entire transaction.�It gives more control when handling large transactions.�
SYNTAX:
BEGIN TRANSACTION;
-- SQL statements
SAVE TRANSACTION savepoint_name;
-- more SQL statements
ROLLBACK TRANSACTION savepoint_name;
-- finally
COMMIT;
ACID Properties
ISOLATION LEVELS
Read UnCommitted:
SYNTAX:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
Read Committed:
A transaction can only read committed data.
SYNTAX:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
Repeatable Read:
SYNTAX:
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Serializable:
Highest level of isolation.
SYNTAX:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
STORED PROCEDURES AND FUNCTIONS
Creating stored procedures
SYNTAX:
CREATE PROCEDURE ProcedureName
@param1 datatype,
@param2 datatype = default_value -- optional
AS
BEGIN
-- SQL statements
END;
IN,OUT,INOUT PARAMAETERS
SQL User Defined Functions
Definition:
1. Scalar Function
2. Inline Table-Valued Function
3. Multi-statement Table-Valued Function
TRIGGERS
Defintion:�A trigger is a stored program in a database that automatically executes (fires) when a specified event occurs in a table or view.It is used to automate processes, enforce rules, maintain logs, or ensure data integrity.
SYNTAX:
CREATE TRIGGER trigger_name
[BEFORE | AFTER | INSTEAD OF]
[INSERT | UPDATE | DELETE]
ON table_name
FOR EACH ROW
BEGIN
-- SQL statements
END;
CREATE TRIGGER trg_AfterInsert
ON Employeess11
AFTER INSERT
AS
BEGIN
END;
BEFORE UPDATE AND AFTER UPDATE
SYNTAX:
CREATE TRIGGER trg_AfterUpdate
ON Employeess11
AFTER UPDATE
AS
BEGIN
END;
SYNTAX
CREATE TRIGGER trg_AfterDelete
ON Employeess11
AFTER DELETE
AS
BEGIN
END;
Users, Roles, and Permissions
GRANT AND REVOKE :
GRANT:
Syntax:
GRANT SELECT, INSERT
ON Employeess11
TO RaviUser;
REVOKE:� It is used to take back permissions that were previously given using GRANT
SYNTAX:
REVOKE INSERT
ON Employeess11
FROM RaviUser;
Normalization
Rule:
Rule:
Partial Dependency = A non-key attribute depends only on part of the composite key.
Rule:
Denormalization:
Denormalization is the process of intentionally adding redundancy to a normalized
database to improve read performance and reduce complex joins.
In simple terms: