0% found this document useful (0 votes)
17 views

Book 16

The document discusses various MySQL commands for data definition, data manipulation, and joining tables. It provides the meaning and syntax for commands related to databases, tables, and queries including create, alter, drop, select, insert, update, delete, join and more.

Uploaded by

sales
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Book 16

The document discusses various MySQL commands for data definition, data manipulation, and joining tables. It provides the meaning and syntax for commands related to databases, tables, and queries including create, alter, drop, select, insert, update, delete, join and more.

Uploaded by

sales
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 2

2.

MYSQL DATABASE COMMANDS (DATA DEFINITION LANGUAGE;DDL)

COMMAND MEANING SYNTAX

show database Shows all the databases available in MySQL server. >SHOW DATABASE;

create database Creates a new database if it does not exist. >CREATE DATABASE DATABASENAME;

drop database To delete an existing database permanently. >DROP DATABASE DATABASE_NAME

alter database Changes or modifies the characteristics of an existing database. >ALTER DATABASE [DATABASENAME] ALTEROPTION ;

Allow you to use a particular database or change from the current >USE DATABASENAME;
use database
database to another database.

3. MySQL Table commands(DDL)

COMMAND MEANING SYNTAX

show tables Shows all tables within the current database. >SHOW TABLES;

>CREATE TABLE TABLENAME (

COLUMN1 DATATYPE,

COLUMN2 DATATYPE,

create table Creates a new table in the current database. COLUMN3 DATATYPE,

....

CONSTRAINTS ....

);

alter table (add column) Adds a new column to an existing table. >ALTER TABLE TABLENAME ADD COLUMNNAME DATATYPE;

alter table (drop column) Deletes a column from an existing table. >ALTER TABLE TABLENAME DROP COLUMN COLUMNNAME;

>ALTER TABLE TABLENAME


alter table (alter column) Alters an existing column in an already existing table.
ALTER COLUMN COLUMNNAME DATATYPE;

>ALTER TABLE TABLENAME


alter table(add primary key) Alters or adds primary key to an existing table.
ADD PRIMARY KEY (COLUMNNAME,...);

>ALTER TABLE TABLENAME


alter table(drop primary key) Drops an existing primary key in a table.
DROP PRIMARY KEY;

>ALTER TABLE TABLENAME1 ADD FOREIGN KEY (COLUMN1) REFERENCES


alter table(add foreign key) Creates a foreign key on an existing table. TABLENAME2(COLUMN2);

alter table(drop foreign key) Deletes an existing foreign key in an already existing table. > ALTER TABLE TABLENAME DROP FOREIGN KEY FOREIGNKEY_NAME;

rename table Changes the name of an existing table. >RENAME TABLE OLD_TABLENAME TO NEW_TABLENAME;

drop table Deletes the entire table along with its definition. >DROP TABLE TABLE_NAME;

truncate table Remove all records in a MySQL table. >TRUNCATE TABLE TABLENAME;

describe table Displays all the columns of an existing table. >DESCRIBE TABLE_NAME;

describe table column Displays all the values stored in a particular column. >DESCRIBE TABLE_NAME COLUMN_NAME;
4. MySQL DML(Data Manipulation Language) Commands

COMMAND MEANING SYNTAX

select * Displays all rows in a table. >SELECT * FROM TABLENAME

select * (multiple tables) Displays all the rows of the cartesian product of the two tables >SELECT * FROM TABLENAME1,TABLENAME2;

select columns Select particular columns from table(s) >SELECT COLUMN1,COLUMN2 FROM TABLENAME;

select with condition Displays rows based on a particular condition > SELECT * FROM TABLENAME WHERE CONDITION

select with multiple


Displays rows only when both the conditions are satisfied. > SELECT * FROM TABLENAME WHERE CONDITION1 AND CONDITION2.
conditions(AND)
select with multiple
Displays rows only when either of the conditions are satisfied. > SELECT * FROM TABLENAME WHERE CONDITION1 OR CONDITION2.
conditions(OR)

select with condition(NOT) Displays rows based on negation of a particular condition. >SELECT * FROM TABLENAME WHERE NOT CONDITION.

select with group by Displays rows that have same values into summary rows > SELECT .. FROM .. WHERE… GROUP BY COLUMN3;

>SELECT COUNT(COLUMN1) FROM TABLENAME ORDER BY COLUMN2 HAVING


select with having Used instead of where for aggregate functions. COUNT(COLUMN1)>3;

select distinct Display all unique rows discarding duplicate ones. >SELECT DISTINCT (COLUMN1) FROM TABLENAME;

order by Used to sort results in ascending order or descending order > SELECT … FROM TABLENAME ORDER BY COLUMN1 ASC|DESC;

column alias Changes the output of the name of the column. > SELECT COLUMN1 AS NEWNAME FROM TABLENAME;

like Used to search for a specific pattern. > SELECT COLUMN1 FROM TABLENAME WHERE COLUMN1 LIKE ‘%PATTERN%’;

insert record Adds a new row to an existing table. > INSERT INTO TABLENAME (COLUMN1,COLUMN2…) VALUES (VALUE1,VALUE2…);

> INSERT INTO TABLENAME (COLUMN1,COLUMN2…) VALUES (VALUE1A,VALUE2A…),


insert record(multiple) Adds multiple records into an existing table. (VALUE1B,VALUE2B,...);

delete Deletes all records in a table. > DELETE FROM TABLENAME;

delete with where Deletes specific records >DELETE FROM TABLENAME WHERE CONDITION;

between Selects values in a given range >SELECT * FROM TABLENAME WHERE AGE BETWEEN 25 AND 30.

in Used instead of multiple OR operators. > SELECT * FROM TABLENAME WHERE COLUMN2 IN (V1,V2…);

exists Tests for existence of a certain record. Returns a boolean value. > SELECT * FROM TABLE NAME WHERE EXIST (SUB QUERY);

update table Modifies data in existing tables. > UPDATE TABLENAME SET COLUMNNAME=VALUE WHERE CONDITION;

Selects records that have the same values in two same or distinct > SELECT COLUMN(S) FROM TABLENAME1 INNER JOIN TABLENAME2 ON
inner join
tables. TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;
Selects all the records from the left table and matching records >SELECT COLUMN(S) FROM TABLENAME1 LEFT JOIN TABLENAME2 ON
left join
from the right table. TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;
Selects all the records from the right table and matching records >SELECT COLUMN(S) FROM TABLENAME1 RIGHT JOIN TABLENAME2 ON
right join
from the left table. TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;

cross join Selects rows from cartesian product of both the tables. >SELECT COLUMN(S) FROM TABLE1 CROSS JOIN TABLE2;

>SELECT COLUMN(S) FROM TABLENAME1 FULL OUTER JOIN TABLENAME2 ON


full outer join Selects all records with a match on table1 or table2. TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME WHERE CONDITION;

>SELECT * FROM TABLENAME1


union Combines the result of two select statements.
UNION SELECT * FROM TABLENAME2

>SELECT * FROM TABLENAME1


union all Similar to Union but allows duplicate values
UNION ALL SELECT * FROM TABLENAME2

>SELECT CONCAT(COLUMN1, " ", POSTALCODE, " ", COLUMN2) AS NEWCOL


concat() Combines two or more columns together.
FROM TABLENAME;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy