\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Arshdeep} \pdfinfo{ /Title (mysql-commands.pdf) /Creator (Cheatography) /Author (Arshdeep) /Subject (MySQL Commands Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1C88A3} \definecolor{LightBackground}{HTML}{F0F7F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{MySQL Commands Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Arshdeep} via \textcolor{DarkBackground}{\uline{cheatography.com/201979/cs/42812/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Arshdeep \\ \uline{cheatography.com/arshdeep} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 23rd March, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Definition Language (DDL) Commands}} \tn % Row 0 \SetRowColor{LightBackground} Command & Explanation & Syntax \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} CREATE TABLE: & Creates a new table in the database with specified columns and constraints. & CREATE TABLE table\_name ( column1 datatype {[}constraint{]}, column2 datatype {[}constraint{]}, ... ); \tn % Row Count 10 (+ 9) % Row 2 \SetRowColor{LightBackground} ALTER TABLE: & Modifies an existing table structure by adding, modifying, or dropping columns or constraints. & Syntax given below: \tn % Row Count 18 (+ 8) % Row 3 \SetRowColor{white} ALTER TABLE table\_name ADD column\_name datatype {[}constraint{]}; & ALTER TABLE table\_name MODIFY column\_name datatype {[}constraint{]}; & ALTER TABLE table\_name DROP COLUMN \seqsplit{column\_name;} \tn % Row Count 23 (+ 5) % Row 4 \SetRowColor{LightBackground} DROP TABLE: & Deletes a table from the database. & DROP TABLE table\_name; \tn % Row Count 26 (+ 3) % Row 5 \SetRowColor{white} TRUNCATE TABLE: & Removes all records from a table, but keeps the table structure intact. & TRUNCATE TABLE table\_name; \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Definition Language (DDL) Commands (cont)}} \tn % Row 6 \SetRowColor{LightBackground} CREATE INDEX: & Creates an index on one or more columns of a table, which speeds up data retrieval operations. & CREATE INDEX index\_name ON table\_name (column1, column2, ...); \tn % Row Count 8 (+ 8) % Row 7 \SetRowColor{white} DROP INDEX: & Removes an index from the database. & DROP INDEX index\_name; \tn % Row Count 11 (+ 3) % Row 8 \SetRowColor{LightBackground} CREATE VIEW: & Creates a virtual table based on the result set of a SELECT query, which can simplify complex queries and provide data security. & CREATE VIEW view\_name AS SELECT column1, column2, ... FROM table\_name WHERE condition; \tn % Row Count 21 (+ 10) % Row 9 \SetRowColor{white} DROP VIEW: & Deletes a view from the database. & DROP VIEW view\_name; \tn % Row Count 24 (+ 3) % Row 10 \SetRowColor{LightBackground} CREATE SCHEMA: & Creates a new schema in the database, which is a logical container for database objects. & CREATE SCHEMA \seqsplit{schema\_name;} \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Definition Language (DDL) Commands (cont)}} \tn % Row 11 \SetRowColor{LightBackground} DROP SCHEMA: & Deletes a schema from the database, along with all its contained objects. & DROP SCHEMA \seqsplit{schema\_name;} \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.1931 cm} x{7.0854 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Manipulation Language (DML) Commands}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{INSERT} INTO: & Adds new records into a table. & INSERT INTO table\_name (column1, column2, ...) VALUES (value1, value2, ...); \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \seqsplit{UPDATE:} & Modifies existing records in a table. & UPDATE table\_name SET column1 = value1, column2 = value2, ... WHERE condition; \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{DELETE} FROM: & Removes records from a table. & DELETE FROM table\_name WHERE condition; \tn % Row Count 13 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{1.687 cm} x{7.5915 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Query Language (DQL) Commands}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{SELECT:} & Retrieves data from one or more tables in a database. & SELECT column1, column2, ... FROM table\_name WHERE condition; \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} FROM: & Specifies the tables from which data is retrieved in a SELECT statement. & SELECT column1, column2, ... FROM table\_name WHERE condition; \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{WHERE:} & Filters rows based on specified conditions in a SELECT statement. & SELECT column1, column2, ... FROM table\_name WHERE condition; \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} GROUP BY: & Explanation: Groups rows that have the same values into summary rows, typically used with aggregate functions like COUNT, SUM, AVG, etc. & SELECT column1, column2, ... FROM table\_name GROUP BY column1, column2, ...; \tn % Row Count 20 (+ 8) % Row 4 \SetRowColor{LightBackground} \seqsplit{HAVING:} & Filters groups based on specified conditions in a GROUP BY query. & SELECT column1, column2, ... FROM table\_name GROUP BY column1 HAVING condition; \tn % Row Count 25 (+ 5) % Row 5 \SetRowColor{white} ORDER BY: & Sorts the result set in ascending or descending order based on one or more columns. & SELECT column1, column2, ... FROM table\_name ORDER BY column1 {[}ASC|DESC{]}; \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{1.687 cm} x{7.5915 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Query Language (DQL) Commands (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \seqsplit{DISTINCT:} & Retrieves unique values from a specific column or combination of columns in a SELECT query. & SELECT DISTINCT column1, column2, ... FROM table\_name; \tn % Row Count 6 (+ 6) % Row 7 \SetRowColor{white} \seqsplit{LIMIT:} & Limits the number of rows returned by a SELECT query. & SELECT column1, column2, ... FROM table\_name LIMIT n; \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{1.687 cm} x{7.5915 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Data Control Language (DCL) Commands}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{GRANT:} & The GRANT command is used to assign specific privileges to database users or roles, allowing them to perform certain actions on database objects. & GRANT privileges ON object TO user; \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} \seqsplit{REVOKE:} & The REVOKE command is used to withdraw previously granted privileges from database users or roles, restricting their access to specific database objects. & REVOKE privileges ON object FROM user; \tn % Row Count 18 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7114 cm} x{6.5793 cm} x{6.5793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Transaction Control Language (TCL) Commands}} \tn % Row 0 \SetRowColor{LightBackground} COMMIT: & Saves the changes made during the current transaction permanently to the database. & COMMIT; \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \seqsplit{ROLLBACK:} & Rolls back the changes made during the current transaction to the last savepoint or the beginning of the transaction. & ROLLBACK; \tn % Row Count 14 (+ 8) % Row 2 \SetRowColor{LightBackground} \seqsplit{SAVEPOINT:} & Sets a named savepoint within the current transaction, allowing partial rollback to that point. & SAVEPOINT \seqsplit{savepoint\_name;} \tn % Row Count 21 (+ 7) % Row 3 \SetRowColor{white} RELEASE \seqsplit{SAVEPOINT:} & Removes a previously defined savepoint, releasing the transaction's resources. & RELEASE SAVEPOINT \seqsplit{savepoint\_name;} \tn % Row Count 27 (+ 6) % Row 4 \SetRowColor{LightBackground} SET \seqsplit{TRANSACTION:} & Sets \seqsplit{characteristics} for the transaction, such as isolation level or read/write mode. & SET TRANSACTION {[}transaction\_characteristics{]}; \tn % Row Count 33 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7114 cm} x{6.5793 cm} x{6.5793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Transaction Control Language (TCL) Commands (cont)}} \tn % Row 5 \SetRowColor{LightBackground} BEGIN \seqsplit{TRANSACTION:} & Begins a new transaction explicitly. & BEGIN TRANSACTION; \tn % Row Count 3 (+ 3) % Row 6 \SetRowColor{white} \seqsplit{ROLLBACK} TO \seqsplit{SAVEPOINT:} & Rolls back the transaction to a specific savepoint. & ROLLBACK TO SAVEPOINT \seqsplit{savepoint\_name;} \tn % Row Count 7 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \end{document}