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

More Related Content

What's hot (17)

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

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

lovely
lovelylovely
lovely
love0323
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
Module 3
Module 3Module 3
Module 3
cs19club
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
SQL | DML
SQL | DMLSQL | DML
SQL | DML
To Sum It Up
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
Introduction to SQL..pdf
Introduction to SQL..pdfIntroduction to SQL..pdf
Introduction to SQL..pdf
mayurisonawane29
 
Database Overview
Database OverviewDatabase Overview
Database Overview
Livares Technologies Pvt Ltd
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLESDATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
NathRam2
 
CS3481_Database Management Laboratory .pdf
CS3481_Database Management Laboratory .pdfCS3481_Database Management Laboratory .pdf
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
DivyaKS12
 
SQL
SQLSQL
SQL
Shyam Khant
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
amitabros
 
Data base
Data baseData base
Data base
Girish Gowda
 
Sql for dbaspresentation
Sql for dbaspresentationSql for dbaspresentation
Sql for dbaspresentation
oracle documents
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLESDATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
NathRam2
 
CS3481_Database Management Laboratory .pdf
CS3481_Database Management Laboratory .pdfCS3481_Database Management Laboratory .pdf
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
DivyaKS12
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
amitabros
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Ad

Recently uploaded (20)

How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
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
  翻译: