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

PPT
Sql basics and DDL statements
PPTX
SQL - DML and DDL Commands
PDF
Sql commands
PPTX
Oracle: DML
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
PPTX
SQL(DDL & DML)
PPTX
STRUCTURE OF SQL QUERIES
ODP
Sql basics and DDL statements
SQL - DML and DDL Commands
Sql commands
Oracle: DML
Database Management - Lecture 2 - SQL select, insert, update and delete
SQL(DDL & DML)
STRUCTURE OF SQL QUERIES

What's hot (17)

PPTX
SQL : Structured Query Language
PPTX
introdution to SQL and SQL functions
PPTX
Sql(structured query language)
PPT
Mysql
PPTX
SQL commands
PPTX
SQL: Structured Query Language
PPTX
SQL Basics
PPTX
Oracle: DDL
PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
PPTX
Sql basic things
PPT
Sql – Structured Query Language
PPTX
Advanced SQL Webinar
PDF
Sql integrity constraints
PDF
Data Manipulation(DML) and Transaction Control (TCL)
PPTX
Null values, insert, delete and update in database
PPTX
Sql basics
PPT
Chapter 07 ddl_sql
SQL : Structured Query Language
introdution to SQL and SQL functions
Sql(structured query language)
Mysql
SQL commands
SQL: Structured Query Language
SQL Basics
Oracle: DDL
SQL Tutorial - How To Create, Drop, and Truncate Table
Sql basic things
Sql – Structured Query Language
Advanced SQL Webinar
Sql integrity constraints
Data Manipulation(DML) and Transaction Control (TCL)
Null values, insert, delete and update in database
Sql basics
Chapter 07 ddl_sql
Ad

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

PDF
SQL for data scientist And data analysist Advanced
PPTX
lovely
PPTX
Lab2 ddl commands
PPTX
SQL: Data Definition Language(DDL) command
DOC
Module 3
PPTX
Introduction to database and sql fir beginers
PPTX
SQL | DML
PPTX
SQL Query
PDF
Introduction to SQL..pdf
PPTX
Database Overview
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
DBMS and SQL(structured query language) .pptx
PPTX
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
PDF
CS3481_Database Management Laboratory .pdf
PPTX
Database models and DBMS languages
PPTX
PDF
Sql tutorial
PPTX
Data base
PDF
Sql for dbaspresentation
PPTX
MySQL Essential Training
SQL for data scientist And data analysist Advanced
lovely
Lab2 ddl commands
SQL: Data Definition Language(DDL) command
Module 3
Introduction to database and sql fir beginers
SQL | DML
SQL Query
Introduction to SQL..pdf
Database Overview
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
DBMS and SQL(structured query language) .pptx
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
CS3481_Database Management Laboratory .pdf
Database models and DBMS languages
Sql tutorial
Data base
Sql for dbaspresentation
MySQL Essential Training
Ad

Recently uploaded (20)

PDF
01-Introduction-to-Information-Management.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Structure & Organelles in detailed.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Lesson notes of climatology university.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Microbial disease of the cardiovascular and lymphatic systems
01-Introduction-to-Information-Management.pdf
Computing-Curriculum for Schools in Ghana
Cell Structure & Organelles in detailed.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Anesthesia in Laparoscopic Surgery in India
Lesson notes of climatology university.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
human mycosis Human fungal infections are called human mycosis..pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Sports Quiz easy sports quiz sports quiz
Microbial disease of the cardiovascular and lymphatic systems

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