Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

MySQL Examples

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 creation
  • insert.sql — data insertion and update
  • consult_control.sql — queries, control, and advanced features

File Overview

Covers database and table creation fundamentals:

  • CREATE DATABASE / CREATE DATABASE IF NOT EXISTS
  • USE, 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, TRUNCATE
  • ALTER TABLE to add columns

Covers data insertion and update operations:

  • INSERT INTO — single and multiple rows in one statement
  • UPDATE … 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

Prerequisites

Running the scripts

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

Concepts Covered

  • DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE
  • DML (Data Manipulation Language): INSERT, UPDATE, DELETE
  • DQL (Data Query Language): SELECT and all its clauses
  • DCL (Data Control Language): GRANT, REVOKE
  • Advanced objects: VIEW, PROCEDURE, TRIGGER

About

Examples for MySQL

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors