0% found this document useful (0 votes)
7 views

SQL [Structured Query Language]

Uploaded by

patilvilohith20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL [Structured Query Language]

Uploaded by

patilvilohith20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Here are the notes on SQL (Structured

Query Language) that cover the key


topics:
1. SQL Basics
• Introduction to SQL: SQL is a standard
language used to interact with relational
databases. It allows users to create, read,
update, and delete data stored in a database.
• Data Types: SQL supports various data types,
including:
o Numeric Types: INT, FLOAT, DECIMAL,
etc.
o Character Types: CHAR, VARCHAR, TEXT,
etc.
o Date and Time Types: DATE, TIME,
DATETIME, etc.
o Boolean: BOOLEAN
• DDL (Data Definition Language) Commands:
Used to define the structure of a database.
o CREATE: Create new tables, databases,
indexes, etc.
o ALTER: Modify existing database objects
like tables.
o DROP: Delete tables, databases, indexes,
etc.
o TRUNCATE: Remove all records from a
table, but not the table itself.
2. SQL DML (Data Manipulation Language)
• SELECT: Retrieve data from one or more
tables.
o Syntax: SELECT column1, column2 FROM
table_name WHERE condition;
• INSERT: Add new records to a table.
o Syntax: INSERT INTO table_name
(column1, column2) VALUES (value1,
value2);
• UPDATE: Modify existing records in a table.
o Syntax: UPDATE table_name SET column1
= value1 WHERE condition;
• DELETE: Remove records from a table.
o Syntax: DELETE FROM table_name
WHERE condition;
3. Advanced SQL
• Joins: Combine rows from two or more tables
based on a related column.
o INNER JOIN: Returns only the rows with
matching values in both tables.
o LEFT JOIN: Returns all rows from the left
table and matched rows from the right
table.
o RIGHT JOIN: Returns all rows from the
right table and matched rows from the
left table.
o FULL OUTER JOIN: Returns all rows when
there is a match in either table.
• Subqueries: Nested queries used to perform
operations on the result of another query.
o Example: SELECT * FROM table1 WHERE
column1 = (SELECT MAX(column1) FROM
table2);
• Aggregate Functions: Perform calculations on
a set of values and return a single value.
o COUNT(), SUM(), AVG(), MAX(), MIN()
• Grouping: Organize data into groups and
perform aggregate functions.
o Syntax: SELECT column1, COUNT(*)
FROM table_name GROUP BY column1;
• Sorting: Arrange data in ascending or
descending order.
o Syntax: SELECT * FROM table_name
ORDER BY column1 ASC;
4. PL/SQL and Triggers
• Introduction to PL/SQL: Procedural Language
extensions to SQL, used for writing complex
queries, loops, and conditions.
• Cursors: Temporary work area created in
memory to execute SQL statements and store
the result.
o Implicit Cursor: Automatically created by
SQL whenever a DML statement is
executed.
o Explicit Cursor: Defined by the user for
queries returning multiple rows.
• Stored Procedures: Precompiled collections
of SQL statements stored under a name and
executed as a unit.
o Syntax: CREATE PROCEDURE
procedure_name AS BEGIN -- SQL
statements END;
• Triggers: Automatically execute a specified
set of SQL statements when a specific event
occurs on a table.
o Syntax: CREATE TRIGGER trigger_name
BEFORE/AFTER INSERT/UPDATE/DELETE
ON table_name FOR EACH ROW BEGIN --
SQL statements END;
These notes provide a comprehensive
overview of SQL, from basic commands
to advanced features like PL/SQL and
triggers.

You might also like