SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Was ist angesagt? (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
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 

Ähnlich wie Basic MySQL queries

Ähnlich wie 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
 

Kürzlich hochgeladen

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
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).pptxEsquimalt MFRC
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
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Ữ Â...Nguyen Thanh Tu Collection
 
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.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
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.docxRamakrishna Reddy Bijjam
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
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 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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.pptxDr. Sarita Anand
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
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.christianmathematics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
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.pptxheathfieldcps1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Kürzlich hochgeladen (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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Ữ Â...
 
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
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
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.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.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.