The+Comprehensive+SQL+Course+PDF
The+Comprehensive+SQL+Course+PDF
SQL Course
Malvik Vaghadia
Contents
Relational Databases
What is MySQL?
What is SQL?
Objects in MySQL
Data Query Language
Data Types
Data Definition and Manipulation Language
Relational Database Design
Operators and the Where Clause
Internal and Metadata Schemas
Functions
Grouping and Aggregating Data
Joining Tables and Set Operators
Order of SQL Operations
Subqueries and Views
Data Control Language
Transaction Control Language
Relational Databases
What is a Database?
A database is a structured collection of digital
information that can be easily accessed, managed, and
organized for various purposes, such as storing,
retrieving, and manipulating data.
What is a Table?
A table is a structured arrangement of data in rows and
columns, commonly used to organize and display
information.
Relational Databases (2)
Benefits of Relational Databases
• Tables adhere to a predefined table structure
• Data types can restrict the type of values that are inserted into
columns
• Constraints can define rules to determine what kind of values are
allowed
• Data Integrity and reliability
• Data remains accurate, consistent, and adheres to predefined
rules, reducing the risk of errors and inconsistencies.
• Databases can store massive amounts of data
• Relational databases can be implemented on cloud infrastructure
and scale up to petabytes of data and beyond
Ordering Rows
Dropping Schemas
Creating Tables
• https://dev.mysql.com/doc/refman/8.0/en/create-table.html
• Anything in square brackets is optional
Dropping Tables
• https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
• Anything in square brackets is optional
Inserting Rows
Truncate Table
Updating Rows
Deleting Rows
Constraints in SQL
Constraints are rules and conditions that are applied to
tables and their columns to ensure the integrity,
accuracy, and consistency of the data stored in a
relational database.
For the UNIQUE and CHECK constraint you will have to use the
syntax below, specifying the unique name given the the
constraint.
Links
String Functions
Numerical Functions
Aggregate Functions
Grouping and
Aggregating Data
Group By Clause
Syntax:
Joining Tables and
Set Operators
Joining Tables
A JOIN operation in SQL is used to combine rows from
two or more tables based on a related column between
them. It enables the retrieval of data that resides in
multiple tables in a single query.
Syntax
JOIN syntax with other clauses
Syntax
Set Operators
The UNION and UNION ALL operators combine all
results from two query blocks into a single result.
UNION omits any duplicates, UNION ALL does not.
Syntax
Syntax:
Data Control
Language
Grant and Revoke
BEGIN; or
START TRANSACTION;
Syntax
Commit a transaction:
COMMIT;
Create a savepoint:
SAVEPOINT savepoint_name;
Rollback to a savepoint:
ROLLBACK TO SAVEPOINT savepoint_name;