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

PPTX
Avinash database
DOCX
Basic sql(oracle) queries
PDF
Sql cheat-sheet
PPTX
Oracle Database DML DDL and TCL
PPT
Tables And SQL basics
PPTX
Linguagem sql
PPTX
SQL - DML and DDL Commands
PPTX
SQL-Alter Table, SELECT DISTINCT & WHERE
Avinash database
Basic sql(oracle) queries
Sql cheat-sheet
Oracle Database DML DDL and TCL
Tables And SQL basics
Linguagem sql
SQL - DML and DDL Commands
SQL-Alter Table, SELECT DISTINCT & WHERE

What's hot (20)

PPT
Sql presentation 1 by chandan
PDF
Database Systems - SQL - DDL Statements (Chapter 3/2)
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DOCX
COMPUTERS SQL
PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
PPT
Sqlbysandeep
PPTX
PPTX
Introduction to database
PPT
Creating a database
PPTX
sql statements & joins
PPT
Sql intro & ddl 1
PPT
MySql slides (ppt)
PPTX
PPTX
SQL(DDL & DML)
DOC
Oracle sql material
PPTX
Sql basic things
PPTX
Sql - Structured Query Language
PDF
PT- Oracle session01
Sql presentation 1 by chandan
Database Systems - SQL - DDL Statements (Chapter 3/2)
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
COMPUTERS SQL
SQL Tutorial - How To Create, Drop, and Truncate Table
Sqlbysandeep
Introduction to database
Creating a database
sql statements & joins
Sql intro & ddl 1
MySql slides (ppt)
SQL(DDL & DML)
Oracle sql material
Sql basic things
Sql - Structured Query Language
PT- Oracle session01
Ad

Similar to Basic MySQL queries (20)

PDF
Sql cheat sheet
PPTX
SQL: Data Definition Language(DDL) command
PPTX
MySQL Essential Training
PDF
Creating, altering and dropping tables
PDF
MySQL notes - Basic Commands and Definitions
PDF
Mysql cheatsheet
PPTX
Difference Between Sql - MySql and Oracle
PPTX
Unit_III_SQL-MySQL-Commands-Basic.pptx usefull
PPTX
SQL : Structured Query Language
PPTX
SQL-SHORT-NOTES.pptx
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
DOCX
Ddl commands
PPTX
Introduction to database and sql fir beginers
PPT
PPTX
SQL-MySQL-Commands-Basic.pptx
PPT
SQL WORKSHOP::Lecture 10
PPTX
DBMS: Week 05 - Introduction to SQL Query
PPTX
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
DOCX
database-querry-student-note
Sql cheat sheet
SQL: Data Definition Language(DDL) command
MySQL Essential Training
Creating, altering and dropping tables
MySQL notes - Basic Commands and Definitions
Mysql cheatsheet
Difference Between Sql - MySql and Oracle
Unit_III_SQL-MySQL-Commands-Basic.pptx usefull
SQL : Structured Query Language
SQL-SHORT-NOTES.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
Ddl commands
Introduction to database and sql fir beginers
SQL-MySQL-Commands-Basic.pptx
SQL WORKSHOP::Lecture 10
DBMS: Week 05 - Introduction to SQL Query
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
database-querry-student-note
Ad

Recently uploaded (20)

PDF
Empowerment Technology for Senior High School Guide
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
International_Financial_Reporting_Standa.pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PPTX
Climate Change and Its Global Impact.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
Hazard Identification & Risk Assessment .pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PPTX
Education and Perspectives of Education.pptx
PPTX
Module on health assessment of CHN. pptx
PDF
Journal of Dental Science - UDMY (2020).pdf
PDF
Literature_Review_methods_ BRACU_MKT426 course material
PDF
CRP102_SAGALASSOS_Final_Projects_2025.pdf
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
Empowerment Technology for Senior High School Guide
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
International_Financial_Reporting_Standa.pdf
Complications of Minimal Access-Surgery.pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
Climate Change and Its Global Impact.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Hazard Identification & Risk Assessment .pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
Education and Perspectives of Education.pptx
Module on health assessment of CHN. pptx
Journal of Dental Science - UDMY (2020).pdf
Literature_Review_methods_ BRACU_MKT426 course material
CRP102_SAGALASSOS_Final_Projects_2025.pdf
Environmental Education MCQ BD2EE - Share Source.pdf
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
Computer Architecture Input Output Memory.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
FORM 1 BIOLOGY MIND MAPS and their schemes

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.