About 3.5-4 hours
Most software applications store data of some sort -- user data, content, etc. Databases are used to store data, so software developers should know how to use them. Relational databases are a common type of database that are good for storing many types of data. Most companies use relational databases to store their data.
Participants will be able to:
- Interact with PostgreSQL through the command line and through a GUI PostgreSQL client such as Postico
- Create database tables
- Add, update, and delete data
- Query data
- Design a basic relational database schema fitting a use case
- Create a table
- Query data from a table
- Filter and limit
- Insert data into a table
- Update
- Delete
- SQL Slides
- Codecademy SQL Tutorial Sections 1-3
- SQL Fiddle to play with SQL queries
- SQL commands are case-insensitive. This is unlike most programming languages! For example, in SQL, these two commands will both do the same thing:
SELECT * FROM food;
select * From fOOd;
- Don't forget the semicolons! SQL commands will only run if you put a semicolon at the end of them.
-
Work through the Codecademy SQL Tutorial Section 1 (Manipulation):
-
PostgreSQL is a popular, open-source version of SQL. Try it out:
- In Terminal, type
psql
to use PostgreSQL. - Try adding a table with the command
CREATE TABLE food (id INTEGER, name TEXT, calories INTEGER);
- See that the table was created by typing
.\dt
to see the list of all existing tables. - Try adding some data:
INSERT INTO food VALUES ("pizza", 500);
- See the data:
SELECT * from food;
- In Terminal, type
-
Using PostgreSQL, try creating tables and adding, updating, deleting, and querying data yourself!
-
Using Postico, try opening the database you just created! Browse the data and get a feel for how to move around. One way to view SQL data is through the command line, and another way is through graphical tools like the Postico.
-
Try writing queries for the following using the
food
table:- Add a column to the table called
meal
- Update "pizza" to have its meal be "dinner"
- Insert 4 more rows into the food DB. Be sure to include values for all 4 columns --
id
,name
,calories
, andmeal
- Update "pizza" to have a different calories number
- Select only the names of all the foods
- Make up a query of your own using another command you've learned
- Add a column to the table called
-
Work through the Codecademy SQL Tutorial Section 2 (Queries)
-
In PostgreSQL, try writing queries for the following using the
food
table. Add some data to the table that meets the criteria below so you'll have something to query for.- Select all foods that have under 100 calories
- Select the names of all foods that start with the letter "a"
- Select all foods that start with "a" AND have meal equal to "dinner"
- Select all foods where meal is "breakfast", sorted by calorie number
- Make up a query of your own using another command you've learned
-
Now do the Codecademy SQL Tutorial Section 3 (Aggregate functions)
-
Try writing queries for the following using the
food
table:- Count the number of rows in the food table
- Find the food with the maximum number of calories
- Find the average number of calories for breakfast food
- Make up a query of your own using another command you've learned
- Another good SQL tutorial: SQL Teaching
- Free SQL Cloud DBs can be created at https://www.elephantsql.com/
- Continue the SQL Codecademy Tutorial (interactive)
- Postico for PostgreSQL
- Khan Academy's introductory SQL(videos)
- TutorialsPoint (detailed)
- Learn SQL the hard way, textbook
- GalaXQL (interactive, graphical)
- PostgreSQL SQL, technical reference manual
- SQLZoo
- A RDBMS Comparison