SlideShare a Scribd company logo
MySQL Notes
Structured Query Language
What is Database?
1. Collection of data
2. A method for accessing and manipulating data
3. A structured set of computerized data with an
accessible interface
Data Definition Language (DDL)
A set of statements that allow the user to define or modify data structures and objects,
such as tables
- CREATE
- ALTER
- DROP
- RENAME
- TRUNCATE
Data Manipulation Language (DML)
Its statements allow us to manipulate the data in the tables of a database
- SELECT… FROM…
- INSERT INTO… VALUES…
- UPDATE… SET… WHERE…
- DELETE FROM… WHERE…
Data Control Language (DCL)
the GRANT and REVOKE statements
allow us to manage the rights users have in a database
GRANT type_of_permission ON database_name.table_name TO ‘username’@’localhost’
REVOKE type_of_permission ON database_name.table_name FROM ‘username’@’localhost’
Transaction Control Language (DCL)
not every change you make to a database is saved automatically
the COMMIT statement
- will save the changes you’ve made
- will let other users have access to the modified version of the database
- related to INSERT, DELETE, UPDATE
the ROLLBACK clause
the clause that will let you make a step back
- allows you to undo any changes you have made but don’t want to be saved permanently
SQL Syntax
DDL – Data Definition Language
SQL Syntax creation of data
DML – Data Manipulation Language
manipulation of data
DCL – Data Control Language
assignment and removal of permissions to use this data
TCL – Transaction Control Language
saving and restoring changes to a database
Primary Key
A column (or a set of columns) whose value exists and is unique for every record in a table
is called a primary key
- each table can have one and only one primary key
- in one table, you cannot have 3 or 4 primary keys
- primary keys are the unique identifiers of a table
- cannot contain null values!
- not all tables you work with will have a primary key
Foreign Key
Identifies the relationships between tables, not the tables themselves
Unique Key
used whenever you would like to specify that you don’t want to see duplicate data
in a given field
Relationships
relationships tell you how much of the data from a foreign key field can be seen in the primary
key column of the table the data is related to and vice versa
types of relationships
- one-to-many (many-to-one)
- one-to-one
- many-to-many
Creating Database
show databases;
CREATE DATABASE
<name>;
CREATE DATABASE
soap_store;
CREATE DATABASE
DogApp;
CREATE DATABASE
My App;
USE <database name>;
SELECT database();
Different Data Types in MySQL
Numeric Types
a. INT
b. SMALLINT
c. TINYINT
d. MEDIUMINT
e. BIGINT
f. DECIMAL
g. NUMERIC
h. FLOAT
i. DOUBLE
j. BIT
Strings Types
a. CHAR
b. VARCHAR
c. BINARY
d. VARBINARY
e. BLOB
f. TINYBLOB
g. MEDIUMBLOB
h. LONGBLOB
i. TEXT
j. TINYTEXT
k. MEDIUMTEXT
l. LONGTEXT
m. ENUM
Date Types
a. DATE
b. DATETIME
c. TIMESTAMP
d. TIME
e. YEAR
Creating Table
CREATE TABLE tablename
(
column_name data_type,
column_name data_type
);
CREATE TABLE cats
(
name VARCHAR(100),
age INT
);
SHOW TABLES;
SHOW COLUMNS FROM <tablename>;
DESC <tablename>;
Deleting Table
DROP TABLE <tablename>;
Insert into Table
INSERT INTO cats(name, age) VALUES ("Jetson", 7);
INSERT INTO cats(name, age) VALUES ('Charlie', 10) ,('Sadie', 3) ,('Lazy Bear', 1);
Using Database and Tables
USE sales;
SELECT * FROM customers;
SELECT * FROM sales.customers;
DROP TABLE sales;
Constraints
Specific rules, or limits, that we define in our tables
- the role of constraints is to outline the existing relationships between different tables in
our database
Example :- NOT NULL
Primary Key
Foreign Key
ON DELETE CASCADE
if a specific value from the parent table’s primary key has been deleted, all the records from the
child table referring to this value will be removed as well
Unique Key
Default Constraint
NOT NULL Constraint
SELECT / WHERE / AND
AND / OR
IN / NOT IN
LIKE / NOT LIKE
BETWEEN …. AND ….
IS NULL / IS NOT NULL
DISTINCT / AGGREGATE FUNCTION
ORDER BY
GROUP BY
HAVING
INSERT
UPDATE
AGGREGATE FUNCTIONS
IFNULL() / COALESCE()
For One Column
For Multiple Columns
INNER JOIN
LEFT JOIN
RIGHT JOIN / SELF JOIN
CROSS JOIN / AGGREGATE FUNCTION WITH JOIN
SUBQUERIES
VIEW
a virtual table whose contents are obtained from an existing table or tables, called base tables
- The view itself does not contain any real data
- the data is physically stored in the base table
- the view simply shows the data contained in the base table

More Related Content

What's hot (17)

PPTX
SQL : Structured Query Language
Abhishek Gautam
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
Sql(structured query language)
Ishucs
 
PPT
Mysql
TSUBHASHRI
 
PPTX
SQL commands
GirdharRatne
 
PPTX
SQL: Structured Query Language
Rohit Bisht
 
PPTX
SQL Basics
Hammad Rasheed
 
PPTX
Oracle: DDL
DataminingTools Inc
 
PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
PPTX
Sql basic things
Nishil Jain
 
PPT
Sql – Structured Query Language
pandey3045_bit
 
PPTX
Advanced SQL Webinar
Ram Kedem
 
PDF
Sql integrity constraints
Vivek Singh
 
PDF
Data Manipulation(DML) and Transaction Control (TCL)
MuhammadWaheed44
 
PPTX
Null values, insert, delete and update in database
Hemant Suthar
 
PPTX
Sql basics
Genesis Omo
 
PPT
Chapter 07 ddl_sql
Nazir Ahmed
 
SQL : Structured Query Language
Abhishek Gautam
 
introdution to SQL and SQL functions
farwa waqar
 
Sql(structured query language)
Ishucs
 
Mysql
TSUBHASHRI
 
SQL commands
GirdharRatne
 
SQL: Structured Query Language
Rohit Bisht
 
SQL Basics
Hammad Rasheed
 
Oracle: DDL
DataminingTools Inc
 
SQL Tutorial - How To Create, Drop, and Truncate Table
1keydata
 
Sql basic things
Nishil Jain
 
Sql – Structured Query Language
pandey3045_bit
 
Advanced SQL Webinar
Ram Kedem
 
Sql integrity constraints
Vivek Singh
 
Data Manipulation(DML) and Transaction Control (TCL)
MuhammadWaheed44
 
Null values, insert, delete and update in database
Hemant Suthar
 
Sql basics
Genesis Omo
 
Chapter 07 ddl_sql
Nazir Ahmed
 

Similar to MySQL notes - Basic Commands and Definitions (20)

PPTX
SQL: Data Definition Language(DDL) command
sonali sonavane
 
PPTX
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
PPTX
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
PPTX
unit-ii.pptx
NilamHonmane
 
PDF
Introduction to SQL..pdf
mayurisonawane29
 
PDF
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
ODP
Mysql database
mayank78634
 
PPTX
Getting Started with MySQL I
Sankhya_Analytics
 
PPT
Sql
jyothislides
 
PDF
Oracle SQL Basics
Dhananjay Goel
 
PDF
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
PPTX
DBMS: Week 05 - Introduction to SQL Query
RashidFaridChishti
 
PPTX
MS SQL - Database Programming Concepts by RSolutions
RSolutions
 
PDF
sql_data.pdf
VandanaGoyal21
 
PDF
DBMS.pdf
Rishab Saini
 
PPTX
Relational Database.pptx
SubhamSarkar64
 
PPTX
sql.pptx
slavskrillex
 
PDF
Introduction to sq lite
punu_82
 
SQL: Data Definition Language(DDL) command
sonali sonavane
 
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
unit-ii.pptx
NilamHonmane
 
Introduction to SQL..pdf
mayurisonawane29
 
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
Mysql database
mayank78634
 
Getting Started with MySQL I
Sankhya_Analytics
 
Oracle SQL Basics
Dhananjay Goel
 
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
DBMS: Week 05 - Introduction to SQL Query
RashidFaridChishti
 
MS SQL - Database Programming Concepts by RSolutions
RSolutions
 
sql_data.pdf
VandanaGoyal21
 
DBMS.pdf
Rishab Saini
 
Relational Database.pptx
SubhamSarkar64
 
sql.pptx
slavskrillex
 
Introduction to sq lite
punu_82
 
Ad

Recently uploaded (20)

PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
'' IMPORTANCE OF EXCLUSIVE BREAST FEEDING ''
SHAHEEN SHAIKH
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
DOCX
A summary of SPRING SILKWORMS by Mao Dun.docx
maryjosie1
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
'' IMPORTANCE OF EXCLUSIVE BREAST FEEDING ''
SHAHEEN SHAIKH
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
A summary of SPRING SILKWORMS by Mao Dun.docx
maryjosie1
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
community health nursing question paper 2.pdf
Prince kumar
 
PPT on the Development of Education in the Victorian England
Beena E S
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Ad

MySQL notes - Basic Commands and Definitions

  • 2. What is Database? 1. Collection of data 2. A method for accessing and manipulating data 3. A structured set of computerized data with an accessible interface
  • 3. Data Definition Language (DDL) A set of statements that allow the user to define or modify data structures and objects, such as tables - CREATE - ALTER - DROP - RENAME - TRUNCATE
  • 4. Data Manipulation Language (DML) Its statements allow us to manipulate the data in the tables of a database - SELECT… FROM… - INSERT INTO… VALUES… - UPDATE… SET… WHERE… - DELETE FROM… WHERE…
  • 5. Data Control Language (DCL) the GRANT and REVOKE statements allow us to manage the rights users have in a database GRANT type_of_permission ON database_name.table_name TO ‘username’@’localhost’ REVOKE type_of_permission ON database_name.table_name FROM ‘username’@’localhost’
  • 6. Transaction Control Language (DCL) not every change you make to a database is saved automatically the COMMIT statement - will save the changes you’ve made - will let other users have access to the modified version of the database - related to INSERT, DELETE, UPDATE the ROLLBACK clause the clause that will let you make a step back - allows you to undo any changes you have made but don’t want to be saved permanently
  • 7. SQL Syntax DDL – Data Definition Language SQL Syntax creation of data DML – Data Manipulation Language manipulation of data DCL – Data Control Language assignment and removal of permissions to use this data TCL – Transaction Control Language saving and restoring changes to a database
  • 8. Primary Key A column (or a set of columns) whose value exists and is unique for every record in a table is called a primary key - each table can have one and only one primary key - in one table, you cannot have 3 or 4 primary keys - primary keys are the unique identifiers of a table - cannot contain null values! - not all tables you work with will have a primary key
  • 9. Foreign Key Identifies the relationships between tables, not the tables themselves Unique Key used whenever you would like to specify that you don’t want to see duplicate data in a given field
  • 10. Relationships relationships tell you how much of the data from a foreign key field can be seen in the primary key column of the table the data is related to and vice versa types of relationships - one-to-many (many-to-one) - one-to-one - many-to-many
  • 11. Creating Database show databases; CREATE DATABASE <name>; CREATE DATABASE soap_store; CREATE DATABASE DogApp; CREATE DATABASE My App; USE <database name>; SELECT database();
  • 12. Different Data Types in MySQL Numeric Types a. INT b. SMALLINT c. TINYINT d. MEDIUMINT e. BIGINT f. DECIMAL g. NUMERIC h. FLOAT i. DOUBLE j. BIT Strings Types a. CHAR b. VARCHAR c. BINARY d. VARBINARY e. BLOB f. TINYBLOB g. MEDIUMBLOB h. LONGBLOB i. TEXT j. TINYTEXT k. MEDIUMTEXT l. LONGTEXT m. ENUM Date Types a. DATE b. DATETIME c. TIMESTAMP d. TIME e. YEAR
  • 13. Creating Table CREATE TABLE tablename ( column_name data_type, column_name data_type ); CREATE TABLE cats ( name VARCHAR(100), age INT ); SHOW TABLES; SHOW COLUMNS FROM <tablename>; DESC <tablename>;
  • 14. Deleting Table DROP TABLE <tablename>; Insert into Table INSERT INTO cats(name, age) VALUES ("Jetson", 7); INSERT INTO cats(name, age) VALUES ('Charlie', 10) ,('Sadie', 3) ,('Lazy Bear', 1);
  • 15. Using Database and Tables USE sales; SELECT * FROM customers; SELECT * FROM sales.customers; DROP TABLE sales;
  • 16. Constraints Specific rules, or limits, that we define in our tables - the role of constraints is to outline the existing relationships between different tables in our database Example :- NOT NULL
  • 18. Foreign Key ON DELETE CASCADE if a specific value from the parent table’s primary key has been deleted, all the records from the child table referring to this value will be removed as well
  • 22. SELECT / WHERE / AND
  • 24. IN / NOT IN
  • 25. LIKE / NOT LIKE
  • 27. IS NULL / IS NOT NULL
  • 28. DISTINCT / AGGREGATE FUNCTION ORDER BY
  • 34. IFNULL() / COALESCE() For One Column For Multiple Columns
  • 37. RIGHT JOIN / SELF JOIN
  • 38. CROSS JOIN / AGGREGATE FUNCTION WITH JOIN
  • 40. VIEW a virtual table whose contents are obtained from an existing table or tables, called base tables - The view itself does not contain any real data - the data is physically stored in the base table - the view simply shows the data contained in the base table