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 (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 (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

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

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

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.