\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{Bayan (Bayan.A)} \pdfinfo{ /Title (dbm.pdf) /Creator (Cheatography) /Author (Bayan (Bayan.A)) /Subject (DBM 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{DBM Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Bayan (Bayan.A)} via \textcolor{DarkBackground}{\uline{cheatography.com/122738/cs/37268/}}} \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}Bayan (Bayan.A) \\ \uline{cheatography.com/bayan-a} \\ \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 19th July, 2023.\\ 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{3.6234 cm} x{5.2704 cm} x{5.1057 cm} x{2.4705 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Entity-Relationship Model:}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Word:}} & {\bf{Definition:}} & {\bf{Example:}} & {\bf{Represented by:}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{Entity Set}} & a group of similar abstract objects. & In a movie database design, movies and stars are entities, and studios are another kind of entity. & \seqsplit{Rectangles} \tn % Row Count 13 (+ 9) % Row 2 \SetRowColor{LightBackground} & It's like a class in \seqsplit{object-oriented} programming but it only defines the structure of data, not operations on data. & They each form an {\bf{entity set.}} & \tn % Row Count 24 (+ 11) % Row 3 \SetRowColor{white} {\bf{Attributes }} & These are properties of entities in an entity set & In a movie database design, attributes could be "title" and "length" for movies & Ovals \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.6234 cm} x{5.2704 cm} x{5.1057 cm} x{2.4705 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Entity-Relationship Model: (cont)}} \tn % Row 4 \SetRowColor{LightBackground} & Attributes are usually implemented as relations, but not all relations come from entity sets & - & \tn % Row Count 8 (+ 8) % Row 5 \SetRowColor{white} & Attributes are of simple types, like strings or numbers. & - & \tn % Row Count 13 (+ 5) % Row 6 \SetRowColor{LightBackground} {\bf{Relationships}} & These are connections between two or more entity sets, such as the "Stars-in" \seqsplit{relationship} between the Movies and Stars entity sets. & & \seqsplit{Diamonds} \tn % Row Count 24 (+ 11) % Row 7 \SetRowColor{white} & A \seqsplit{relationship} means that an entity in one set is connected to an entity in another set. & & \tn % Row Count 32 (+ 8) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.6234 cm} x{5.2704 cm} x{5.1057 cm} x{2.4705 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Entity-Relationship Model: (cont)}} \tn % Row 8 \SetRowColor{LightBackground} & Binary \seqsplit{relationships} between two entity sets are most common, but the E/R model allows for any number of entity sets to be involved in a \seqsplit{relationship}. & & \tn % Row Count 13 (+ 13) % Row 9 \SetRowColor{white} Tuple & a row in a table in a database, \seqsplit{representing} a unique instance of an entity or a combination of entities & & \tn % Row Count 22 (+ 9) % Row 10 \SetRowColor{LightBackground} & It contains values for each attribute of the entity. & & \tn % Row Count 27 (+ 5) % Row 11 \SetRowColor{white} \seqsplit{Instances} of an E/R \seqsplit{Diagram:} & describe database schemas, and while no actual data exists in the E/R model, it can be useful to visualize it as if it did. & & \tn % Row Count 38 (+ 11) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.6234 cm} x{5.2704 cm} x{5.1057 cm} x{2.4705 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{17.67cm}}{\bf\textcolor{white}{Entity-Relationship Model: (cont)}} \tn % Row 12 \SetRowColor{LightBackground} & Entities have values for each attribute, and \seqsplit{relationships} connect entities & & \tn % Row Count 7 (+ 7) % Row 13 \SetRowColor{white} & The instance of a \seqsplit{relationship} is a set of tuples that are connected by the \seqsplit{relationship}. & & \tn % Row Count 15 (+ 8) % Row 14 \SetRowColor{LightBackground} & These tuples are not the same as those in a relation, and their components are entities instead of primitive types. & & \tn % Row Count 25 (+ 10) % Row 15 \SetRowColor{white} & Each row of the table \seqsplit{representing} the \seqsplit{relationship} set is a list of connected entities from different entity sets. & & \tn % Row Count 35 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.181 cm} x{12.089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Keys}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Keys }} & an attribute or set of attributes which helps you to identify a row(tuple) in a relation (table) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} & They allow you to find the relation between two tables \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Candidate Key}} & The minimal set of attributes that can uniquely identify a tuple(row) is known as a candidate key \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} & The value of the Candidate Key is unique and non-null for every tuple \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} & All are "prime attributes." Same as candidate key. \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} {\bf{Primary Key}} & There can be more than one candidate key in relation out of which one can be chosen as the primary key \tn % Row Count 19 (+ 4) % Row 6 \SetRowColor{LightBackground} & Exactly one \tn % Row Count 20 (+ 1) % Row 7 \SetRowColor{white} & Every primary key is unique and non-null \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} & Whichever is most flexible for us can be used as a primary key \tn % Row Count 25 (+ 3) % Row 9 \SetRowColor{white} & Primary key(PK) is a subset of a Candidate key(CK) \tn % Row Count 27 (+ 2) % Row 10 \SetRowColor{LightBackground} & There can be one or more CK, but exactly one PK \tn % Row Count 29 (+ 2) % Row 11 \SetRowColor{white} {\bf{Alternate key}} & The candidate key other than the primary key is called an alternate key \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.181 cm} x{12.089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Keys (cont)}} \tn % Row 12 \SetRowColor{LightBackground} & Out of EmployeeNum, Driving\_license and PermitNumber, if EmployeeNum is selected as Primary Key, then the Driving\_license and PermitNumber automatically become the Alternate Keys \tn % Row Count 7 (+ 7) % Row 13 \SetRowColor{white} {\bf{Super keys}} & The set of attributes that can uniquely identify a tuple(row) is known as a Super Key \tn % Row Count 11 (+ 4) % Row 14 \SetRowColor{LightBackground} & Two keys together that create a unique attribute is a super key \tn % Row Count 14 (+ 3) % Row 15 \SetRowColor{white} & Adding zero or more attributes to the candidate key generates the super key \tn % Row Count 17 (+ 3) % Row 16 \SetRowColor{LightBackground} & You can say every candidate key is a super key, but vice versa is not true. \tn % Row Count 20 (+ 3) % Row 17 \SetRowColor{white} {\bf{Foreign Key}} & Foreign keys are the column of the table which is used to point to the primary key of another table. \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5264 cm} x{11.7436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Weak/Strong Entity Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Weak Entity Types:}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{A Weak Entity Type is an entity type that does not have sufficient attributes to form a primary ke} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{The existence of a weak entity depends on the existence of an identifying or owner entity type.} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{The relationship between them is called an identifying (ID) relationship.} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{The identifying relationship type is always many-to-one from the weak entity type to the identifying entity type.} \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{The weak entity type must have a discriminator (one or more attributes) for distinguishing among its entities.} \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{For example, in an employees database, Child entities exist only if their corresponding Parent employee entity exists.} \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{{\bf{Weak Entity Types in an ERD:}}} \tn % Row Count 17 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{A weak entity type is identified by a double rectangle.} \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{The discriminator is underlined by a dashed line.} \tn % Row Count 20 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{An identifying relationship is identified by a double diamond.} \tn % Row Count 22 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{The fact that the existence of the weak entity requires the existence of an owner entity is captured by the total participation of the weak entity type in the relationship (double line).} \tn % Row Count 26 (+ 4) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{The primary key of a weak entity type is the combination of the primary key of its owner type and its discriminator, e.g., (NI\#, Cname) for Child.} \tn % Row Count 29 (+ 3) % Row 13 \SetRowColor{white} Strong Entity & An entity with a Primary Key \tn % Row Count 31 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.9359 cm} x{14.3341 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Single \& Mutliple-table Queries}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{SELECT} & desired attributes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} FROM & one or more tables \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} WHERE & conditions on rows of the tables are satisfied \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{DELETE} & Delete rows from a table based on a specific condition \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} & e.g DELETE FROM table\_name WHERE condition; \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} AVG & calculate the average of a numeric column in a table? \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} & e.g.SELECT AVG(column\_name) FROM table\_name; \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{DISTINCT} & retrieve unique values in a column or a set of columns. \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}