SlideShare a Scribd company logo
1 of 3
MySQL Queries
DDL (Data definition language)
DATABASE
TABLE
Create database CREATE DATABASE<database_name>;
Show databases list SHOW DATABASES;
Select/Use database USE<database_name>;
Delete/Drop database DROP DATABASE<database_name>;
Create table CREATE TABLE <table_name>
(< column_name1><datatype> [<constraint>],
< column_name2><datatype>
[<constraint>],…);
Show tables list SHOW TABLES;
Describe table(table structure) DESCRIBE<table_name>;
Delete/Drop table DROP TABLE<table_name>;
Rename table ALTER TABLE<old_table_name>
RENAME TO<new_table_name>;
Add a column ALTER TABLE <table name>
ADD <new_column_name><datatype>
[<constraint>];
Rename a column ALTER TABLE <table name>
CHANGE
<old_column_name><new_column_name><datat
ype>[<constraint>];
Delete a column ALTER TABLE <table name>
DROP <column_name>;
Modify datatype or
size
ALTER TABLE <table name>
MODIFY <column_name><datatype>
[<constraint>];
COLUMN
CONSTRAINTS
Constrain
ts
Add constraint Drop constraint
Not null ALTER TABLE <table name>
MODIFY <column_name><datatype>NOT
NULL;
ALTER TABLE <table name>
MODIFY
<column_name><datatype>NUL
DML (Data Manipulation language)
INSERT
Insert into all columns INSERT INTO <table_name>
VALUES(<column1_value>,< column2_value>,……);
Insert into specific columns INSERTINTO<table_name> (<column1>, <column2>,…)
VALUES(<column1_value>, <column2_value>,……);
SELECT
Select all data (all rows all columns –
full table)
SELECT *
FROM<table_name>;
Select specific columns SELECT<column1, column2,….>
FROM <table_name>;
Select all data based on condition SELECT *
FROM<table_name> WHERE <condition>;
Select data in ascending/descending
order
SELECT *
FROM<table_name>
ORDER BY <column1><ascending/descending>;
UPDATE
Update values which satisfy condition UPDATE<table_name>
SET<column_name>=<new_value>;
Update all values of a specific
column(same values for a particular
column)
UPDATE<table_name>
SET<column_name>=<new_value>
WHERE<condition>;
L;
Unique ALTER TABLE <table name>
ADD CONSTRAINT <constraint_name>
UNIQUE (<column_name>);
ALTER TABLE <table name>
DROP INDEX
<constraint_name>;
Check ALTER TABLE <table name>
ADD CONSTRAINT <constraint_name>
CHECK (<column_name><condition>);
ALTER TABLE <table name>
DROP CHECK
<constraint_name>;
Primary
key
ALTER TABLE <table name>
MODIFY <column_name><datatype>
PRIMARY KEY;
ALTER TABLE <table name>
DROP PRIMARY KEY;
Default ALTER TABLE <table name>
ALTER <column_name>
SET DEFAULT<value>;
ALTER TABLE <table name>
ALTER <column_name> DROP
DEFAULT;
Foreign key ALTER TABLE <table name>
ADD CONSTRAINT <constraint_name>
FOREIGN KEY (<column_name>)
REFERENCES <table
name1>(<column_name>);
ALTER TABLE <table name>
DROP FOREIGN KEY
<constraint_name>;
DELETE
Delete specific rows based on
condition
DELETE
FROM <table_name>
WHERE <condition>;
Clear all data of a table(delete all
rows)
DELETE
FROM <table_name>;
Identifiers-
An Identifier is essentially a name of a database_name, table_name, column_name or
constraint_name.
Rules-
1. First letter must be alphabet (a-z, A-Z).
2. Second and other letters can be numbers (0-9), alphabet (a-z, A-Z) and _ (underscore).
3. Must not be a keyword.

More Related Content

What's hot

Creating a database
Creating a databaseCreating a database
Creating a database
Rahul Gupta
 

What's hot (20)

Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
1 ddl
1 ddl1 ddl
1 ddl
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 
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
 
Sqlbysandeep
SqlbysandeepSqlbysandeep
Sqlbysandeep
 
SQL
SQLSQL
SQL
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Creating a database
Creating a databaseCreating a database
Creating a database
 
sql statements & joins
sql statements & joinssql statements & joins
sql statements & joins
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Introduction to mysql part 1
Introduction to mysql part 1Introduction to mysql part 1
Introduction to mysql part 1
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 

Viewers also liked

My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
leminhvuong
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Structured query language
Structured query languageStructured query language
Structured query language
Neeti Gupta
 
Dot net interview_questions
Dot net interview_questionsDot net interview_questions
Dot net interview_questions
9292929292
 

Viewers also liked (20)

Software Development : Change Request Template
Software Development : Change Request TemplateSoftware Development : Change Request Template
Software Development : Change Request Template
 
Sql server difference faqs- 3
Sql server difference faqs- 3Sql server difference faqs- 3
Sql server difference faqs- 3
 
Basic MySQL queries
Basic MySQL queriesBasic MySQL queries
Basic MySQL queries
 
SQL: The Language of Databases
SQL: The Language of DatabasesSQL: The Language of Databases
SQL: The Language of Databases
 
Select Queries
Select QueriesSelect Queries
Select Queries
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Basics of dml queries
Basics of dml queriesBasics of dml queries
Basics of dml queries
 
Sql
SqlSql
Sql
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
 
Query execution
Query executionQuery execution
Query execution
 
SQL
SQLSQL
SQL
 
SQL: Querying Multiple Tables
SQL: Querying Multiple TablesSQL: Querying Multiple Tables
SQL: Querying Multiple Tables
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Structured query language
Structured query languageStructured query language
Structured query language
 
Dot net interview_questions
Dot net interview_questionsDot net interview_questions
Dot net interview_questions
 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
 
PL/SQL Tips and Techniques Webinar Presentation
PL/SQL Tips and Techniques Webinar PresentationPL/SQL Tips and Techniques Webinar Presentation
PL/SQL Tips and Techniques Webinar Presentation
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 

Similar to Basic MySQL queries

Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tables
punu_82
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
Umair Amjad
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
Leerpiny Makouach
 

Similar to Basic MySQL queries (20)

Sql cheat sheet
Sql cheat sheetSql cheat sheet
Sql cheat sheet
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tables
 
MySQL notes - Basic Commands and Definitions
MySQL notes - Basic Commands and DefinitionsMySQL notes - Basic Commands and Definitions
MySQL notes - Basic Commands and Definitions
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
Unit_III_SQL-MySQL-Commands-Basic.pptx usefull
Unit_III_SQL-MySQL-Commands-Basic.pptx  usefullUnit_III_SQL-MySQL-Commands-Basic.pptx  usefull
Unit_III_SQL-MySQL-Commands-Basic.pptx usefull
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
SQL-SHORT-NOTES.pptx
SQL-SHORT-NOTES.pptxSQL-SHORT-NOTES.pptx
SQL-SHORT-NOTES.pptx
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
Les09
Les09Les09
Les09
 
SQL-MySQL-Commands-Basic.pptx
SQL-MySQL-Commands-Basic.pptxSQL-MySQL-Commands-Basic.pptx
SQL-MySQL-Commands-Basic.pptx
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
MySQL
MySQLMySQL
MySQL
 
Les10
Les10Les10
Les10
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Basic MySQL queries

  • 1. MySQL Queries DDL (Data definition language) DATABASE TABLE Create database CREATE DATABASE<database_name>; Show databases list SHOW DATABASES; Select/Use database USE<database_name>; Delete/Drop database DROP DATABASE<database_name>; Create table CREATE TABLE <table_name> (< column_name1><datatype> [<constraint>], < column_name2><datatype> [<constraint>],…); Show tables list SHOW TABLES; Describe table(table structure) DESCRIBE<table_name>; Delete/Drop table DROP TABLE<table_name>; Rename table ALTER TABLE<old_table_name> RENAME TO<new_table_name>; Add a column ALTER TABLE <table name> ADD <new_column_name><datatype> [<constraint>]; Rename a column ALTER TABLE <table name> CHANGE <old_column_name><new_column_name><datat ype>[<constraint>]; Delete a column ALTER TABLE <table name> DROP <column_name>; Modify datatype or size ALTER TABLE <table name> MODIFY <column_name><datatype> [<constraint>]; COLUMN CONSTRAINTS Constrain ts Add constraint Drop constraint Not null ALTER TABLE <table name> MODIFY <column_name><datatype>NOT NULL; ALTER TABLE <table name> MODIFY <column_name><datatype>NUL
  • 2. DML (Data Manipulation language) INSERT Insert into all columns INSERT INTO <table_name> VALUES(<column1_value>,< column2_value>,……); Insert into specific columns INSERTINTO<table_name> (<column1>, <column2>,…) VALUES(<column1_value>, <column2_value>,……); SELECT Select all data (all rows all columns – full table) SELECT * FROM<table_name>; Select specific columns SELECT<column1, column2,….> FROM <table_name>; Select all data based on condition SELECT * FROM<table_name> WHERE <condition>; Select data in ascending/descending order SELECT * FROM<table_name> ORDER BY <column1><ascending/descending>; UPDATE Update values which satisfy condition UPDATE<table_name> SET<column_name>=<new_value>; Update all values of a specific column(same values for a particular column) UPDATE<table_name> SET<column_name>=<new_value> WHERE<condition>; L; Unique ALTER TABLE <table name> ADD CONSTRAINT <constraint_name> UNIQUE (<column_name>); ALTER TABLE <table name> DROP INDEX <constraint_name>; Check ALTER TABLE <table name> ADD CONSTRAINT <constraint_name> CHECK (<column_name><condition>); ALTER TABLE <table name> DROP CHECK <constraint_name>; Primary key ALTER TABLE <table name> MODIFY <column_name><datatype> PRIMARY KEY; ALTER TABLE <table name> DROP PRIMARY KEY; Default ALTER TABLE <table name> ALTER <column_name> SET DEFAULT<value>; ALTER TABLE <table name> ALTER <column_name> DROP DEFAULT; Foreign key ALTER TABLE <table name> ADD CONSTRAINT <constraint_name> FOREIGN KEY (<column_name>) REFERENCES <table name1>(<column_name>); ALTER TABLE <table name> DROP FOREIGN KEY <constraint_name>;
  • 3. DELETE Delete specific rows based on condition DELETE FROM <table_name> WHERE <condition>; Clear all data of a table(delete all rows) DELETE FROM <table_name>; Identifiers- An Identifier is essentially a name of a database_name, table_name, column_name or constraint_name. Rules- 1. First letter must be alphabet (a-z, A-Z). 2. Second and other letters can be numbers (0-9), alphabet (a-z, A-Z) and _ (underscore). 3. Must not be a keyword.