Skip to content

Commit

Permalink
update database slides from post-class feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
saragibby committed Apr 23, 2017
1 parent a03bfa2 commit ff44dbd
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 487 deletions.
245 changes: 244 additions & 1 deletion class1.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,256 @@ <h3>Let's Develop It!</h3>
<p>Create a sample database and fill it with data.<p>
<br/>
<p>Download install files from: <a href="http://bit.ly/gdiaa-dvdrental">http://bit.ly/gdiaa-dvdrental</a></p>
<br />
<h4 class="green">Couple Ways to Load Sample Database...</h4>
<ol>
<li><code>psql</code> Prompt</li>
<li>Restore in pgAdmin</li>
</ol>
</section>


<section>
<h3>Let's Develop It!</h3>
<h4 class="green">From <code>psql</code> Prompt</h4>
<br/>
<p>Open Terminal go to where you downloaded the <strong>dvdrental.tar</strong> file.</p>
<code>createdb dvdrental</code>
<br/>
<code>pg_restore -d dvdrental dvdrental.tar</code>
</section>


<section>
<section>
<h3>Let's Develop It!</h3>
<br/>
<h4 class="green">Restore in pgAdmin</h4>
<ol>
<li>Create <code>dvdrental</code> database</li>
<li>Pick option to "Restore" to that database</li>
<li>Select <code>dvdrental.tar</code> </li>
</ol>
</section>

<section>
<h3>Let's Develop It!</h3>
<img src="images/create-database-option.png" class="left img--bare"/>
<img src="images/create-database.png" style="width: 45%" class="pull-right img--bare" />
</section>

<section>
<h3>Let's Develop It!</h3>
<img src="images/restore-database-option.png" class="left img--bare"/>
<img src="images/select-tar-from-all-files.png" style="width: 60%" class="pull-right img--bare" />
</section>
</section>


<section>
<h3>Let's Develop It!</h3>
<p>Checkout our dvdrental database in pgAdmin.<p>
<ol>
<li>Open <strong>pgAdmin</strong> tool</li>
<li>Expand <strong>Servers</strong></li>
<li>Expand <strong>localhost</strong></li>
<li>Expand <strong>Databases</strong></li>
<li>Expand our new database <strong>dvdrental</strong></li>
<ol>
</section>

<section>
<h3>Pieces and parts of a relational database</h3>
<p>A relational database consists of many different elements, some of which include: </p>
<div style="float: left; width: 50%;" class="copy--small">
<ul>
<li>schema</li>
<li>tables</li>
<li>views</li>
<li>relationships</li>
<li>indexes</li>
</ul>
</div>
<div style="float: left; width: 50%;" class="copy--small">
<ul>
<li>functions</li>
<li>stored procedures</li>
<li>triggers</li>
<li>server objects</li>
<li>and other elements</li>
</ul>
</div>
</section>

<section>
<h3>Schema</h3>
<ul>
<li class ="fragment">Is a way to logically group database objects</li>
<li class ="fragment">Acts as a blueprint for how the database is constructed</li>
<li class ="fragment">In a relational database, the schema defines relationships, tables, fields in tables etc.</li>
</ul>
</section>

<section>
<h3>Tables</h3>
<p>In a relational database, a table is an organized set of data using columns and rows.</p>
<img src="images/table.gif" class="img--bare" />
<p>You may sometimes hear a table referred to as a "relation".</p>
</section>

<section>
<h3>Let's Develop It!</h3>
<p>Spend a few minutes exploring DVD Rental database<p>
<ol>
<li>Expand <strong>Schemas</strong></li>
<li>Checkout <strong>Tables</strong></li>
<li>Right click on a table, select option to view data</li>
</ol>
</section>

<section>
<h3>The SELECT Statement</h3>
<ul>
<li class ="fragment">We use the <code>SELECT</code> command to show/query data from a database</li>
<li class ="fragment">The output from a <code>SELECT</code> statement is always a grid of rows and columns.</li>
<li class ="fragment">The most simple <code>SELECT</code> statement retrieves all values from a single table</li>
<li class ="fragment"><code>SELECT</code> columns <code>FROM</code> database</li>
</ul>
</section>

<section>
<h3>Let's Develop It!</h3>
<p>Explore the dvdrental tables & data.</p>
<ul style="width: 50%">
<li>Right-click on <strong>dvdrental</strong></li>
<li>Select <strong>Query Tool</strong></li>
</ul>
<br/><br/>
<p class="copy--small" style="width: 50%; padding-left: 20px"><span class="green"><em>Note:</em></span> SQL is not case sensitive</p>

<pre><code contenteditable class="JavaScript">SELECT * FROM actor;
</code></pre>
<p>This will return all of the results from the actor table.</p>
</section>

<section>
<h3>SELECT DISTINCT</h3>
<p><code>DISTINCT</code> keyword is used to return only distinct values, if there are duplicate values</p>

<p class="copy--small left-align"><span class="green"><em>Note:</em></span> Some database systems require a semi colon after each SQL statement. PostgreSQL is one of them.</p>

<div class="box--small"><pre><code contenteditable class="terminal">SELECT distinct first_name FROM actor;
</code></pre></div>
<p>This will return a distinct list of first names from the actor table in the dvdrentals db</p>
</section>

<section>
<h3>The WHERE Clause</h3>
<p class="copy--small">Returns a subset of rows filtered on the <code>WHERE</code> clause criteria</p>
<p class="copy--small"><code>SELECT</code> .. <code>WHERE</code> statement can be made on one line:</p>
<br/>
<p class="copy--small left-align" style="padding-left: 20px"><span class="green"><em>Note:</em></span> PostgreSQL uses double-quotes to look for internal database object. Use single-quote to wrap string values.</p>
<pre><code contenteditable class="JavaScript">SELECT * FROM actor WHERE first_name = 'Bette';</code></pre>
</section>

<section>
<h3>WHERE Clause Operators</h3>
<table style="font-size: 20px; line-height: 1.4em;">
<tr>
<td><strong>Operator</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td>=</td>
<td>Equal</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>Not equal. <em>Note:</em> In some versions of SQL, this may be written as !=</td>
</tr>
<tr>
<td>&gt;</td>
<td>Greater than</td>
</tr>
<tr>
<td>&lt;</td>
<td>Less than</td>
</tr>
<tr>
<td>&gt;=</td>
<td>Greater than or equal</td>
</tr>
<tr>
<td>&lt;=</td>
<td>Less than or equal</td>
</tr>
<tr>
<td>BETWEEN</td>
<td>Between an inclusive range</td>
</tr>
<tr>
<td>LIKE</td>
<td>Search for a pattern (can use a wildcard character)</td>
</tr>
<tr>
<td>IN</td>
<td>To specify multiple possible values for a column</td>
</tr>
</table>
</section>

<section>
<h3>Not Equal</h3>
<pre><code contenteditable class="JavaScript">SELECT * FROM actor WHERE first_name <> 'Catherine';
</code></pre>
</section>

<section>
<h3>Greater Than</h3>
<pre><code contenteditable class="JavaScript">SELECT * FROM rental WHERE rental_date > '2005-12-31';
</code></pre>
</section>

<section>
<h3>Less Than</h3>
<pre><code contenteditable class="JavaScript">SELECT * FROM film WHERE rental_duration < 4;
</code></pre>
</section>

<section>
<h3>BETWEEN</h3>
<pre><code contenteditable class="JavaScript">SELECT * FROM film WHERE replacement_cost BETWEEN 21.99 AND 24.99;
</code></pre>
</section>

<section>
<h3>LIKE</h3>
<p>Uses the wildcard character</p>
<pre><code contenteditable class="JavaScript">SELECT * FROM customer WHERE last_name LIKE '%Will%';
</code></pre>
<p>Can use the character at the beginning or end of the word/phrase</p>
<pre><code contenteditable class="JavaScript">SELECT * FROM customer WHERE last_name LIKE 'Will%';
</code></pre>
</section>

<section>
<h3>IN</h3>
<pre><code contenteditable class="JavaScript">SELECT * FROM film WHERE rating IN ('G', 'PG');
</code></pre>
</section>

<section>
<h3>Let's Develop It!</h3>
<ul>
<li>Spend some time writing SELECT statements with WHERE clauses</li>
<li>Feel free to work with a neighbor!</li>
<li>Practice Problems:</li>
<ul>
<li>Return all films that have an id greater than 900</li>
<li>Return all customers with a Last name of 'Smith'</li>
<li>Return all payment over 7 dollars</li>
</ul>
</ul>
</section>

<section>
<section>
Expand Down
Loading

0 comments on commit ff44dbd

Please sign in to comment.