-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from LaunchCodeEducation/sql-1
SQL Part 1
- Loading branch information
Showing
14 changed files
with
531 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
+++ | ||
title = "Installing Azure Data Studio" | ||
date = 2024-02-12T13:42:28-06:00 | ||
draft = false | ||
weight = 6 | ||
+++ | ||
|
||
Azure Data Studio is a tool that allows us to work with data that is either stored on our machine and on servers that we need to connect to. Maintained by Microsoft, Azure Data Studio is the premier tool for users of all operating systems to work with SQL Server. | ||
|
||
[Download and install Azure Data Studio](https://learn.microsoft.com/en-us/azure-data-studio/download-azure-data-studio?tabs=win-install%2Cwin-user-install%2Credhat-install%2Cwindows-uninstall%2Credhat-uninstall) | ||
|
||
{{% notice blue Note %}} | ||
|
||
If you are a Mac user, make sure to select the correct chip type for your machine! | ||
|
||
{{% /notice %}} | ||
|
||
## Working with Notebooks in Azure Data Studio | ||
|
||
Watch the first 3 minutes and 20 seconds of the video below for a nice overview of getting started with Azure Data Studio. | ||
|
||
[Azure Data Studio Introduction](https://www.youtube.com/watch?v=4HpBJkjA-M8&list=PLW_iKqdGFW0zS688xkUV56ZxfDaUqZ6kD&index=5) | ||
|
||
{{% notice blue Note %}} | ||
|
||
During the video, he goes over how to connect to a server. The login info for the server you will need to connect to for this class can be found in the "Class 11 Setup: Azure Data Studio" assignment in Canvas. | ||
|
||
{{% /notice %}} | ||
|
||
We will continue to use notebooks, however, now we will be opening our notebooks in Azure Data Studio. There are some differences running notebooks in Azure Data Studio, which the below video goes into more detail on. | ||
|
||
[Quick intro to SQL Notebooks in Azure Data Studio](https://www.youtube.com/watch?v=Csd9p1-0Y_c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
+++ | ||
pre = "<b>18. </b>" | ||
chapter = true | ||
title = "SQL Part 1" | ||
date = 2024-03-21T15:06:12-05:00 | ||
draft = false | ||
weight = 18 | ||
+++ | ||
|
||
## Learning Objectives | ||
|
||
Upon completing all the content in this chapter, you should be able to do the following: | ||
|
||
1. Understand what a relational database is and how SQL is used to manage it. | ||
1. Write SQL queries to perform read operations. | ||
1. Understand different types of table relationships and what foreign/primary keys are. | ||
|
||
## Key Terminology | ||
|
||
Here is a list of key terms for this chapter, based on what page the term first appears. Make note of these terms and their definitions. | ||
|
||
### What is SQL? | ||
|
||
1. Relational databases | ||
1. Structured Query Language | ||
1. SQL | ||
1. Relational Database Management System | ||
1. RDMS | ||
1. Transact-SQL | ||
1. T-SQL | ||
|
||
### SQL Queries | ||
|
||
1. query | ||
1. result set | ||
1. CRUD | ||
|
||
### Table Relationships | ||
|
||
1. primary key | ||
1. foreign key | ||
|
||
## Content Links | ||
|
||
{{% children %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
+++ | ||
title = "Exercises: SQL Intro" | ||
date = 2021-10-01T09:28:27-05:00 | ||
draft = false | ||
weight = 2 | ||
+++ | ||
|
||
## Getting Started | ||
|
||
In Azure Data Studio, open up `SQL-Part-1-Exercises.ipynb` in `data-analysis-projects/sql-part-1/exercises`. | ||
|
||
## In Your Notebook | ||
|
||
Connect to `BooksDB`. If you need a refresher on how to do this, see Setup Azure Data Studio. | ||
|
||
## Submitting Your Work | ||
|
||
When finished, make sure to push your changes up to GitHub. | ||
|
||
Copy the link to your GitHub repository and paste it into the submission box in Canvas for **Exercises: SQL Part 1** and click *Submit*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
+++ | ||
title = "Next Steps" | ||
date = 2021-10-01T09:28:27-05:00 | ||
draft = false | ||
weight = 4 | ||
+++ | ||
|
||
You are now ready to move on to part 2 of learning more about SQL. If you want some additional resources on the topics we just covered, here are a few of our favorites. | ||
|
||
1. [W3Schools SQL Tutorial](https://www.w3schools.com/sql/default.asp) | ||
1. [Difference Between Primary and Foreign Key](https://www.geeksforgeeks.org/difference-between-primary-key-and-foreign-key/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
+++ | ||
title = "Reading" | ||
date = 2024-03-21T15:06:12-05:00 | ||
draft = false | ||
weight = 1 | ||
+++ | ||
|
||
## Reading Content | ||
|
||
{{% children %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
+++ | ||
title = "What is SQL?" | ||
date = 2021-10-01T09:28:27-05:00 | ||
draft = false | ||
weight = 1 | ||
+++ | ||
|
||
So far, we have used spreadsheets and DataFrames to hold data. However, both of these are limited in how much information they can store. | ||
This is where a relational database comes in. | ||
|
||
**Relational databases** store data in tables, which are connected to each other in a variety of different ways. | ||
Tables contain columns and rows of information, with each column specifying the data type of the information within, and each row having a unique key. | ||
Relational databases provide flexibility for both expansion of the database and modification of the relationships between the tables as things change. | ||
|
||
In order to access our information, we need to use a tool that can talk to a relational database. | ||
**Structured Query Language** or **SQL** is the main tool used by programmers to work with these data structures. | ||
SQL is a **Relational Database Management System** or **RDMS**. | ||
We can use SQL to perform many essential operations on a database, such as adding and removing data. | ||
|
||
## Transact-SQL | ||
|
||
There are many different types of SQL. For this class, we will be using **Transact-SQL** or **T-SQL**. T-SQL is the pre-eminent form of SQL for managing large data stores and is an extension of the SQL language maintained by Microsoft. | ||
|
||
{{% notice blue Note %}} | ||
|
||
Throughout this course, we will be referring to T-SQL as SQL. This is common in industry and it can be assumed that when you hear SQL, the speaker is referring to T-SQL. | ||
|
||
{{% /notice %}} | ||
|
||
To get started with the chapter, you need to [install Azure Data Studio]({{% relref "./../../../installations/install-azure-data" %}}) and connect to the instance of SQL server. | ||
|
||
SQL has many of the same data types you have already worked with so far in this course. However, some of the types, like `string`, have a different name in SQL. | ||
|
||
### Numbers | ||
|
||
For integers, we will be using the `int` data type. As you grow in your career, you may see others such as `bigint` or `tinyint` in SQL databases. | ||
The [SQL documentation](https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16) offers a full breakdown of these different integer types. | ||
|
||
SQL also has a `decimal` data type that is similar to what we have already seen with `double` in Python. | ||
|
||
### Strings | ||
|
||
There is no `string` type in SQL. Instead, we use the `varchar` type. | ||
`varchar` produces a string of variable length, but we have to tell SQL how long the string will be *at a maximum*. | ||
Therefore, when we use `varchar` in a declaration, we add the maximum number of characters like so: `VARCHAR(250)`. That declaration specifies that the string will be, at a maximum, 250 characters. | ||
|
||
### Boolean | ||
|
||
SQL does not support boolean data types for columns, but it can support a `bit` data type. A `bit` data type can either be `1` to represent true, `0` to represent false, or `NULL`. | ||
|
||
## Check Your Understanding | ||
|
||
{{% notice green Question %}} | ||
|
||
Which of the following are supported data types in SQL? Select ALL that are correct. | ||
|
||
1. `tinyint` | ||
1. `int` | ||
1. `double` | ||
1. `varchar` | ||
1. `boolean` | ||
1. `string` | ||
|
||
{{% /notice %}} | ||
|
||
<!-- 1,2,3,4 --> |
Oops, something went wrong.