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
Ad

Recommended

PPT
Sql basics and DDL statements
Mohd Tousif
 
PPTX
SQL - DML and DDL Commands
Shrija Madhu
 
PDF
Sql commands
Mohd Tousif
 
PPTX
Oracle: DML
DataminingTools Inc
 
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
PPTX
SQL(DDL & DML)
Sharad Dubey
 
PPTX
STRUCTURE OF SQL QUERIES
VENNILAV6
 
ODP
Sql commands
Balakumaran Arunachalam
 
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
 
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
 

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)

DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
PPTX
Martyrs of Ireland - who kept the faith of St. Patrick.pptx
Martin M Flynn
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
VCE Literature Section A Exam Response Guide
jpinnuck
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
DLL english grade five goof for one week
FlordelynGonzales1
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Martyrs of Ireland - who kept the faith of St. Patrick.pptx
Martin M Flynn
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
VCE Literature Section A Exam Response Guide
jpinnuck
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
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