\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{RuneHansen} \pdfinfo{ /Title (sql-server.pdf) /Creator (Cheatography) /Author (RuneHansen) /Subject (SQL server 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{SQL server Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{RuneHansen} via \textcolor{DarkBackground}{\uline{cheatography.com/67523/cs/16986/}}} \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}RuneHansen \\ \uline{cheatography.com/runehansen} \\ \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 7th September, 2018.\\ 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}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Information:}} \tn % Row 0 \SetRowColor{LightBackground} Data & Data is information which comes in different types. Like Names, Age or height. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Database & Database is used to store data Systematically, which also makes it easier to handle a lot of data. It is also known as a logical world. \tn % Row Count 11 (+ 7) % Row 2 \SetRowColor{LightBackground} Database Mangement System & 4 Types - Hierachichal, Network, Relational and Object Oriented (which is the some used to save data in TABLE format). \tn % Row Count 17 (+ 6) % Row 3 \SetRowColor{white} Structured Query Language (SQL) & SQL can be used to INSERT, SEARCH, UPDATE and DELETE database records. SQL also helps optimizing and maintaining databases. \tn % Row Count 23 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.344 cm} x{3.496 cm} p{0.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Installation}} \tn % Row 0 \SetRowColor{LightBackground} Step 1. & Launch, "SQL Server Installation Center", through an ISO. Before installing run, "System configuration Checker", to make sure you do not have any block in installing the software. & \tn % Row Count 11 (+ 11) % Row 1 \SetRowColor{white} Step 2. & After test run, go to "installation tab" choose "New SQL stand-alone" to get a complete new SQL Server or the possibility to change existing SQL server. & \tn % Row Count 20 (+ 9) % Row 2 \SetRowColor{LightBackground} Step 3. & Through setup, make sure to add an administrative account, to access your SQL server. & \tn % Row Count 25 (+ 5) % Row 3 \SetRowColor{white} Step 4. & You will now have the proper SQL features and application installed. & \tn % Row Count 29 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{} \tn % Row Count 29 (+ 0) % Row 5 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{SQL Server Tools:} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.344 cm} x{3.496 cm} p{0.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Installation (cont)}} \tn % Row 6 \SetRowColor{LightBackground} {\bf{Server manager configuration}} & Contains many settings like Network configuration settings. used for establishing the services that we expect to be running while the server is up are actually running. & \tn % Row Count 10 (+ 10) % Row 7 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{} \tn % Row Count 10 (+ 0) % Row 8 \SetRowColor{LightBackground} {\bf{SQL Server Management Studio}} & Install on SQL Server through ISO or browser. System databases are installed for you as you install a new instance of SQL, which will be shown in the management studio. & \tn % Row Count 20 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Server roles}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{Sysadmin}} & Can perform all activities on the database Engine instance. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\emph{Serveradmin}} & Members can perform instance-wide configuration tasks. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\emph{Securityadmin}} & Manage instance-level permissions. \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\emph{Processadmin}} & Can terminate processes running on a database \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} {\emph{Setupadmin}} & Can add/remove linked servers from the database. \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} {\emph{Bulkadmin}} & Allow the use of BULK INSERT statement on databases hosted on an instance. \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} {\emph{Diskadmin}} & Members can manage instance related files. \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} {\emph{Dbcreator}} & Create, alter, drop and restore databases hosted in an instance. \tn % Row Count 19 (+ 3) % Row 8 \SetRowColor{LightBackground} {\emph{Public}} & All logins are members of this role. \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Database roles}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{DBowner}} & Allow all database configuration and management task. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\emph{DBsecurityadmin}} & allow the management on membership of fixed and flexible database-level-roles. \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\emph{DBaccessadmin}} & assign to security principals, who needs to manage database access for logins. \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\emph{DBbackupoperator}} & allows backup role. \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\emph{DBddladmin}} & Be able to run any data definition language (DDL) command in the database \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\emph{DBdatawriter}} & allow modification on a user's Table such as "insert" and "delete". \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} {\emph{DBdatareader}} & Allow the user to read all data from user tables. \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} {\emph{DBdenydatawriter}} & Deny inserting, altering or deleting data from a database's user tables. \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} {\emph{DBdenydatareader}} & deny a user to read data stored within a database's user tables. \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} p{0.76 cm} x{3.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Requirements:}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) % Row 1 \SetRowColor{white} {\bf{Software:}} & & {\bf{Hardware: }} \tn % Row Count 1 (+ 1) % Row 2 \SetRowColor{LightBackground} - .Net 3.5 SP1 is a requirement for SQL Server 2012 & & - SQL server 2012 requires minimum 6 GB HDD \tn % Row Count 5 (+ 4) % Row 3 \SetRowColor{white} - .Net 4.0 is a requirement that will be installed automatically during feature Installation Step. & & - Super VGA (800x600) or Higher resolution \tn % Row Count 12 (+ 7) % Row 4 \SetRowColor{LightBackground} - Powershell is a requirement & & - Minimum Ram 512 MB, recommended 1 GB (for Express edition) - 1 GB, 4 GB recommended (all other editions) \tn % Row Count 18 (+ 6) % Row 5 \SetRowColor{white} - Internet explorer 7 or later versions. & & - Minimum Processor speed X86 Processor (1.0 GHz), x64 Processor (1.4 GHz) Recommended 2.0 GHz or faster. \tn % Row Count 24 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{4 types of system databases}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Master database}} & - Most important out of the four databases. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & - Contains system level information for the instance you're in. \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} & - Holds information of other databases you create. \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} & - Contains the initialization information for the SQL server, without it, the instance can't start. \tn % Row Count 11 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 11 (+ 0) % Row 5 \SetRowColor{white} {\bf{Model Database}} & - Act as a template for any database added to your instance \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} & - All settings, objects, tables and basically all changes will be added to all databases you create. \tn % Row Count 18 (+ 4) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 18 (+ 0) % Row 8 \SetRowColor{LightBackground} {\bf{Msdb}} & - Management system database, has multiple jobs \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} & - Tracks the SQ server agent which is used to shut your regular jobs like regular backups or data import/export jobs. \tn % Row Count 25 (+ 5) % Row 10 \SetRowColor{LightBackground} & - List all the backups and restores done in the instance. \tn % Row Count 28 (+ 3) % Row 11 \SetRowColor{white} & - Take regular backups of this database that it contains valuable information \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{4 types of system databases (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) % Row 13 \SetRowColor{white} {\bf{Tempdb}} & - Holds all temporary objects, created by you and by the database itself \tn % Row Count 3 (+ 3) % Row 14 \SetRowColor{LightBackground} & - It will delete all changes and objects when the instance gets restarted. \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Useful SQL Commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Requesting a single column:}} & SELECT "Columnname" \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} With " , " you can add more & FROM "Tablename" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 4 (+ 0) % Row 3 \SetRowColor{white} {\bf{Request All}} & SELECT * \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} & FROM "Tabel-name" \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 6 (+ 0) % Row 6 \SetRowColor{LightBackground} {\bf{writing to Tabel}} & INSERT INTO "tabelname" \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} & VALUES ("Write the value of a given Column) \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 10 (+ 0) % Row 9 \SetRowColor{white} {\bf{Selective search}} & SELECT "Columnname" \tn % Row Count 12 (+ 2) % Row 10 \SetRowColor{LightBackground} & FROM "Tabelname" \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} & WHERE "Columnname" = "Value in column" \tn % Row Count 15 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 15 (+ 0) % Row 13 \SetRowColor{white} {\bf{Creating Tabel}} & CREATE TABEL "tabelname" \tn % Row Count 17 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 17 (+ 0) % Row 15 \SetRowColor{white} {\bf{Delete option}} & DELETE FROM "tabelname" \tn % Row Count 19 (+ 2) % Row 16 \SetRowColor{LightBackground} & WHERE "value" \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}