\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.pdf) /Creator (Cheatography) /Author (Arshdeep) /Subject (MySQL 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}{2564A3} \definecolor{LightBackground}{HTML}{F1F5F9} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Arshdeep} via \textcolor{DarkBackground}{\uline{cheatography.com/201979/cs/42811/}}} \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{multicols*}{2} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Databases}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Database is an organized collection of related information.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Databases support storage and manipulation of data} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{We need databases to store large amounts of information, to keep data organized, to protect data, to analyze data, and to scale with demand.} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{ACID Properties}} \tn % Row 0 \SetRowColor{LightBackground} ACID properties are fundamental for ensuring data reliability, consistency, and integrity in database systems. & They provide a set of guarantees that enable transactions to operate correctly in a multi-user environment. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} Applications requiring strict data integrity and reliability, such as banking systems, e-commerce platforms, and inventory management systems, rely heavily on ACID-compliant databases. & Relational database management systems (RDBMS) like Oracle, MySQL, and PostgreSQL typically adhere to the ACID properties to ensure data consistency and reliability. \tn % Row Count 16 (+ 10) % Row 2 \SetRowColor{LightBackground} Atomicity: Refers to the all-or-nothing principle. Ensures that a transaction is either completed in its entirety or not at all. If any part of a transaction fails, the entire transaction is rolled back, preserving data integrity. & Consistency: Guarantees that the database remains in a valid state before and after the execution of transactions. Enforces integrity constraints and rules defined for the database. All changes made by a transaction must adhere to the predefined consistency constraints. \tn % Row Count 30 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{ACID Properties (cont)}} \tn % Row 3 \SetRowColor{LightBackground} Isolation: Ensures that concurrent execution of transactions produces results equivalent to those achieved through serial execution. Transactions appear to execute in isolation from each other, even though they may be executed concurrently. Prevents interference between transactions, maintaining data integrity and consistency. & Durability: Ensures that once a transaction is committed, its effects persist even in the event of system failures. Changes made by committed transactions are permanent and are stored in non-volatile memory (such as disk) to withstand crashes or restarts. Guarantees that committed transactions survive system failures and are not lost or rolled back. \tn % Row Count 18 (+ 18) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{NoSQL}} \tn % Row 0 \SetRowColor{LightBackground} NoSQL databases are non-relational databases designed for handling large volumes of unstructured, semi-structured, or structured data. & They offer flexible schema design and horizontal scalability to manage diverse data types and high-velocity data ingestion. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Flexible Schema: NoSQL databases allow dynamic schema creation, enabling storage of varying data structures within the same database. & Horizontal Scalability: NoSQL databases scale horizontally by adding more servers or nodes to distribute data and load across the cluster. \tn % Row Count 14 (+ 7) % Row 2 \SetRowColor{LightBackground} High Performance: Designed for high-speed data processing and low-latency access, making them suitable for real-time applications. & Distributed Architecture: Data is distributed across multiple nodes, providing fault tolerance and redundancy for increased reliability. \tn % Row Count 21 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Normalization}} \tn % Row 0 \SetRowColor{LightBackground} Definition: The process of organizing data in a database to reduce redundancy and dependency. & Objective: Enhance data integrity, minimize anomalies, and improve database efficiency. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} First Normal Form (1NF): Ensures atomicity of data. No repeating groups or arrays. & Second Normal Form (2NF): Non-key attributes are fully functionally dependent on the primary key. Eliminates partial dependencies. \tn % Row Count 12 (+ 7) % Row 2 \SetRowColor{LightBackground} Third Normal Form (3NF): Eliminates transitive dependencies. Non-key attributes depend only on the primary key. & Boyce-Codd Normal Form (BCNF): A stronger version of 3NF. Every determinant is a candidate key. Avoids certain types of anomalies. \tn % Row Count 19 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Database Management System (DBMS)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{DBMS is a collection of programs that enables its users to access databases, manipulate data, reporting/representation of data.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{DBMS manages the data, the database engine, and the database schema, allowing for data to be manipulated or extracted by users or other programs.} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types of DBMS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Relational DBMS (RDBMS) Organizes data into tables with rows and columns. Utilizes Structured Query Language (SQL) for data manipulation. Examples: MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{NoSQL DBMS Suited for unstructured or semi-structured data. Offers flexibility in schema design. Types: Document-oriented, Key-value, Column-oriented, Graph databases. Examples: MongoDB, Cassandra, Redis, Neo4j.} \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Object-Oriented DBMS (OODBMS) Stores data in the form of objects. Supports object-oriented features like inheritance and encapsulation. Examples: db4o, ObjectDB.} \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Graph DBMS Optimized for managing and querying graph data structures. Ideal for interconnected data applications like social networks. Examples: Neo4j, Amazon Neptune, JanusGraph.} \tn % Row Count 18 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Time-Series DBMS Specialized for managing data with timestamps. Commonly used in IoT and financial data analysis. Examples: InfluxDB, TimescaleDB, Prometheus.} \tn % Row Count 22 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{In-Memory DBMS Stores data primarily in system memory for faster access. Suitable for applications requiring high-speed data processing. Examples: Redis, MemSQL, VoltDB.} \tn % Row Count 26 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{RDBMS}} \tn % Row 0 \SetRowColor{LightBackground} RDBMS is a type of database management system that stores data in the form of tables with rows and columns. & Data is organized into related tables, and relationships between tables are established using keys. It employs Structured Query Language (SQL) for querying and managing the database. \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} Tables: Data is stored in tables consisting of rows and columns. & Rows: Each row represents a record or entity in the database. \tn % Row Count 14 (+ 4) % Row 2 \SetRowColor{LightBackground} Columns: Each column represents a specific attribute or field of the data. & Keys: Primary keys uniquely identify each row in a table, while foreign keys establish relationships between tables. \tn % Row Count 20 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types of NoSQL}} \tn % Row 0 \SetRowColor{LightBackground} Document Store: Stores semi-structured data in flexible JSON or BSON documents. Example: MongoDB, Couchbase, CouchDB. & Key-Value Store: Simplest NoSQL model, storing data as key-value pairs. Example: Redis, Amazon DynamoDB, Riak. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} Column Family Store: Organizes data into columns instead of rows, suitable for wide-column databases. Example: Apache Cassandra, HBase. & Graph Database: Designed for managing highly interconnected data, using graph structures. Example: Neo4j, Amazon Neptune, JanusGraph. \tn % Row Count 13 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{SQL}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Definition: Standardized language for managing relational databases.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Designed for querying, updating, and managing data.} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Tips:} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Use aliases to simplify column names in queries.} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Utilize indexes for faster data retrieval.} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Regularly backup and maintain databases to prevent data loss.} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{SQL Data Types}} \tn % Row 0 \SetRowColor{LightBackground} String Data Types: TEXT, CHAR, VARCHAR, ENUM, SET & Numeric Data Types: INT, FLOAT, DOUBLE, etc. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Date and Time Data Types: DATE, TIME, TIMESTAMP, DATETIME, YEAR & JSON Data Type: Store JSON documents in the JSON column \tn % Row Count 7 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}