\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{MNMO} \pdfinfo{ /Title (sql-cheat-sheet-mohamed-ahmed.pdf) /Creator (Cheatography) /Author (MNMO) /Subject (SQL\_Cheat\_Sheet\_Mohamed\_Ahmed 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}{4766FF} \definecolor{LightBackground}{HTML}{F3F5FF} \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{SQL\_Cheat\_Sheet\_Mohamed\_Ahmed Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{MNMO} via \textcolor{DarkBackground}{\uline{cheatography.com/135369/cs/28078/}}} \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}MNMO \\ \uline{cheatography.com/mnmo} \\ \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 24th January, 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{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Data Base}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE DATABASE DatabaseName;} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{DROP DATABASE DatabaseName;} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SHOW DATABASES;} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{USE DatabaseName;} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Create \& Delete Table}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Create Table:}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{CREATE TABLE table\_name(} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{column1 datatype,} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{column3 datatype,} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{.....} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{columnN datatype,} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{PRIMARY KEY( one or more columns ) );} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} CREATE TABLE CUSTOMERS(`} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`ID INT NOT NULL,`} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`NAME VARCHAR (20) NOT NULL,`} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`AGE INT NOT NULL,`} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`ADDRESS CHAR (25) ,`} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`SALARY DECIMAL (18, 2),`} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`PRIMARY KEY (ID));`} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Creating a Table from an Existing Table:}}} \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{CREATE TABLE NEW\_TABLE\_NAME AS} \tn % Row Count 16 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT {[} column1, column2...columnN {]}} \tn % Row Count 17 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM EXISTING\_TABLE\_NAME} \tn % Row Count 18 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{[} WHERE {]}} \tn % Row Count 19 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{DROP or DELETE Table:}}} \tn % Row Count 20 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{DROP TABLE table\_name;} \tn % Row Count 21 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Constraints}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`CREATE TABLE CUSTOMERS( `} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`ID INT NOT NULL,`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`NAME VARCHAR (20) NOT NULL,`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`AGE INT NOT NULL UNIQUE,`} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`ADDRESS CHAR (25),`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SALARY DECIMAL (18, 2) DEFAULT 5000.00,`} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`PRIMARY KEY (ID) );`} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Appling Constraints By:}}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{ALTER TABLE Table\_Name Column MODIFY CONSTRAINT;} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Dropping Constraints By:}}} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{ALTER TABLE Table\_Name Column DROP CONSTRAINT;} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• NOT NULL Constraint: Ensures that a column cannot have a NULL value.}}} \tn % Row Count 13 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\emph{You must use the IS NULL or IS NOT NULL operators to check for a NULL value.}}} \tn % Row Count 15 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} SELECT`} \tn % Row Count 16 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`ID, NAME, AGE, ADDRESS, SALARY`} \tn % Row Count 17 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`FROM CUSTOMERS`} \tn % Row Count 18 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`WHERE SALARY IS NOT NULL;`} \tn % Row Count 19 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• DEFAULT Constraint: Provides a default value for a column when none is specified. }}} \tn % Row Count 21 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• UNIQUE Constraint: Ensures that all values in a column are different. }}} \tn % Row Count 23 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• PRIMARY Key: Uniquely identifies each row/record in a database table.}}} \tn % Row Count 25 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• FOREIGN Key: Uniquely identifies row/record in any of the given database tables. The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table.}}} \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Constraints (cont)}} \tn % Row 21 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• CHECK Constraint: The CHECK constraint ensures that all the values in a column satisfies certain conditions.}}} \tn % Row Count 3 (+ 3) % Row 22 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• INDEX: Used to create and retrieve data from the database very quickly. it is assigned a ROWID for each row before it sorts out the data.}}} \tn % Row Count 6 (+ 3) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE INDEX index\_name} \tn % Row Count 7 (+ 1) % Row 24 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{ON table\_name ( column1, column2.....);} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Constraints}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE TABLE CUSTOMERS( \newline ID INT NOT NULL, \newline NAME VARCHAR (20) NOT NULL, \newline AGE INT NOT NULL UNIQUE, \newline ADDRESS CHAR (25), \newline SALARY DECIMAL (18, 2) DEFAULT 5000.00, \newline PRIMARY KEY (ID) );} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Query's for Manipulating Tables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{INSERT:}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{INSERT INTO TABLE\_NAME (column1, column2, column3,...columnN){]}} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{VALUES (value1, value2, value3,...valueN);} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{SELECT:}}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2, columnN FROM table\_name;} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{UPDATE:}}} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{UPDATE table\_name} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SET column1 = value1, column2 = value2...., columnN = valueN} \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition{]};} \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{DELETE:}}} \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{DELETE FROM table\_name} \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition{]};} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{ORDER BY Clause \& SORTING Results}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\emph{ascending or descending order, ascending order by default.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SELECT column-list} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{[}WHERE condition{]}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{[}ORDER BY column1, column2, .. columnN{]} {[}ASC | DESC{]};} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{TOP, LIMIT or ROWNUM Clause}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT TOP number|percent column\_name(s)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition{]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} SELECT TOP 3 * FROM CUSTOMERS;`} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} SELECT * FROM CUSTOMERS LIMIT 3;`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} SELECT * FROM CUSTOMERS WHERE ROWNUM \textless{}= 3;`} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{WHERE Clause}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2, column} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition{]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\emph{You can specify a condition using the comparison or logical operators like \textgreater{}, \textless{}, =, LIKE, NOT,AND,OR.}}} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{The AND | OR Operator}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2, column} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition1{]} AND | OR {[}condition2{]}...AND | OR {[}conditionN{]};} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{LIKE | Wildcard}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{• The percent sign (\%)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{• The underscore (\_)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT FROM table\_name} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{WHERE column {[}LIKE | Wildcard{]} {[}'XXXX\%' | '\%XXXX\%' | 'XXXX\_' | '\_XXXX' | '\_XXXX\_'{]}} \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{GROUP BY}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[} conditions {]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{GROUP BY column1, column2} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{ORDER BY column1, column2} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{HAVING Clause}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table1, table2} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[} conditions {]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{GROUP BY column1, column2} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{HAVING {[} conditions {]}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{ORDER BY column1, column2} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Distinct Keyword}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT DISTINCT column1, column2,.....columnN} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table\_name} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{WHERE {[}condition{]}} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{UNION | UNION ALL | INTERSECT | EXCEPT}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning any duplicate rows.}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\emph{To use this UNION clause, each SELECT statement must have}}} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• The same number of columns selected}}} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• The same number of column expressions}}} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• The same data type}}} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• Have them in the same order}}} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SELECT column1 {[}, column2 {]}} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{FROM table1 {[}, table2 {]} {[}WHERE condition{]}} \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{[}UNION | UNION ALL | INTERSECT | EXCEPT{]}} \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SELECT column1 {[}, column2 {]}} \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{FROM table1 {[}, table2 {]} {[}WHERE condition{]}} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Joins}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\emph{There are different types of joins available in SQL:}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• INNER JOIN: returns rows when there is a match in both tables.}}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• INNER JOIN: returns rows when there is a match in both tables.}}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left table.}}} \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• FULL JOIN: returns rows when there is a match in one of the tables.}}} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SELECT table1.column1, table2.column2... FROM table1} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{[}INNER JOIN | LEFT JOIN | RIGHT JOIN | FULL JOIN{]} table2} \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{ON table1.common\_field = table2.common\_field;} \tn % Row Count 16 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• SELF JOIN: is used to join a table to itself as if the table were two tables, temporarily renaming at least one table in the SQL statement.}}} \tn % Row Count 19 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`SQL\textgreater{} SELECT`} \tn % Row Count 20 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`a.ID, b.NAME, a.SALARY`} \tn % Row Count 21 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`FROM CUSTOMERS a, CUSTOMERS b`} \tn % Row Count 22 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`WHERE a.SALARY \textless{} b.SALARY;`} \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Alias}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{The basic syntax of a table alias}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SELECT column1, column2.... FROM table\_name AS alias\_name WHERE {[}condition{]};} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{The basic syntax of a column alias}}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SELECT column\_name AS alias\_name FROM table\_name WHERE {[}condition{]};} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Indexes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE INDEX index\_name ON table\_name;} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Single-Column Indexes }}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE INDEX index\_name ON table\_name (column\_name);} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Unique Indexes}}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{CREATE UNIQUE INDEX index\_name on table\_name (column\_name);} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{DROP INDEX}}} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{DROP INDEX index\_name;} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{When should indexes be avoided? \newline The following guidelines indicate when the use of an index should be reconsidered. \newline •Indexes should not be used on small tables. \newline •Tables that have frequent, large batch updates or insert operations. \newline •Indexes should not be used on columns that contain a high number of NULL values. \newline •Columns that are frequently manipulated should not be indexed.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Using Views}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\emph{which are a type of virtual tables allow}} \newline {\emph{users to do the following:}} \newline {\bf{• Structure data in a way that users or }} \newline {\bf{classes of users find natural or intuitive.}} \newline {\bf{• Restrict access to the data in such a way}} \newline {\bf{that a user can see and (sometimes) modify}} \newline {\bf{exactly what they need and no more.}} \newline {\bf{• Summarize data from various tables which}} \newline {\bf{can be used to generate reports.}} \newline {\bf{CREATE VIEW}} \newline CREATE VIEW view\_name AS \newline SELECT column1, column2..... \newline FROM table\_name \newline WHERE {[}condition{]}; \newline {\bf{Dropping Views}} \newline DROP VIEW view\_name;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Transactions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Transactions have the following four standard }} \newline {\bf{properties, usually referred to by the acronym ACID.}} \newline {\bf{• Atomicity: ensures that all operations within the work}} \newline {\bf{unit are completed successfully. Otherwise, the transaction}} \newline {\bf{is aborted at the point of failure and all the previous}} \newline {\bf{operations are rolled back to their former state.}} \newline {\bf{• Consistency: ensures that the database properly changes}} \newline {\bf{states upon a successfully committed transaction.}} \newline {\bf{• Isolation: enables transactions to operate independently }} \newline {\bf{of and transparent to each other.}} \newline {\bf{• Durability: ensures that the result or effect of a committed}} \newline {\bf{transaction persists in case of a system failure.}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Transaction Control}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\emph{The following commands are used to control transactions.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• COMMIT: to save the changes.}}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{COMMIT;} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• ROLLBACK: to roll back the changes.}}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{ROLLBACK;} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{• SAVEPOINT: creates points within the groups of transactions in which to ROLLBACK.}}} \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{SAVEPOINT SAVEPOINT\_NAME;} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{ROLLBACK TO SAVEPOINT\_NAME;} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• SET TRANSACTION: Places a name on a transaction.}}} \tn % Row Count 12 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SET TRANSACTION {[} READ WRITE | READ ONLY {]};} \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{• The RELEASE SAVEPOINT Command}}} \tn % Row Count 14 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{RELEASE SAVEPOINT SAVEPOINT\_NAME;} \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}