A collection of annotated SQL scripts covering the core concepts of MySQL — from database creation to advanced queries, access control, views, stored procedures, and triggers. Written in Brazilian Portuguese.
The files are divided into three categories:
create.sql— database and table creationinsert.sql— data insertion and updateconsult_control.sql— queries, control, and advanced features
Covers database and table creation fundamentals:
CREATE DATABASE/CREATE DATABASE IF NOT EXISTSUSE,SHOW DATABASES,SHOW TABLES,DESCRIBE- Table creation with
PRIMARY KEY,AUTO_INCREMENT,NOT NULL,UNIQUE - MySQL data types:
INT,FLOAT,DECIMAL,VARCHAR,TEXT,DATE,DATETIME,TIMESTAMP,BOOLEAN,BLOB - Foreign keys with
CONSTRAINT,REFERENCES,ON DELETE,ON UPDATE UPDATE,DELETE,DROP TABLE,DROP DATABASE,TRUNCATEALTER TABLEto add columns
Covers data insertion and update operations:
INSERT INTO— single and multiple rows in one statementUPDATE … SET … WHERE- Data validation rules: types, nullability, uniqueness, foreign key integrity, and field length
Covers querying, control, and advanced features:
| Topic | Commands / Concepts |
|---|---|
| Basic queries | SELECT, WHERE, ORDER BY |
| Joins | INNER JOIN, LEFT JOIN, RIGHT JOIN, UNION |
| Pattern matching | LIKE (%, _) |
| Range filters | BETWEEN, NOT BETWEEN |
| Aggregation | DISTINCT, COUNT, AVG, GROUP BY |
| Math operations | +, -, *, /, %, column aliases (AS) |
| Access control | GRANT, REVOKE |
| Views | CREATE VIEW, SELECT FROM view |
| Stored Procedures | CREATE PROCEDURE, DELIMITER, IN parameters |
| Triggers | CREATE TRIGGER, BEFORE INSERT, FOR EACH ROW, NEW |
- MySQL 8.0+ (or compatible MariaDB version)
- A MySQL client such as:
- MySQL Workbench
- DBeaver
- MySQL CLI (
mysql)
Run the scripts in order using the MySQL CLI:
# 1. Connect to your MySQL server
mysql -u root -p
# 2. Create the database and tables
source /path/to/MySQL-examples/create.sql
# 3. Insert sample data
source /path/to/MySQL-examples/insert.sql
# 4. Run queries and explore control features
source /path/to/MySQL-examples/consult_control.sql- DDL (Data Definition Language):
CREATE,ALTER,DROP,TRUNCATE - DML (Data Manipulation Language):
INSERT,UPDATE,DELETE - DQL (Data Query Language):
SELECTand all its clauses - DCL (Data Control Language):
GRANT,REVOKE - Advanced objects:
VIEW,PROCEDURE,TRIGGER