4 hours
- Desire to learn more about databases.
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.
Apprentices will be able to:
- 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
- Joins
- Insert data into a table
- Update
- Delete
- Khan Academy's introductory SQL, videos
- W3Schools Tutorial, interactive
- Codecademy Tutorial, interactive
- Learn SQL the hard way, textbook
- GalaXQL, interactive, graphical
- PostgreSQL SQL, technical reference manual
- SQL Fiddle
- SQLZoo
- A RDBMS Comparison
SQL (video walkthrough of slides)
-
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: https://www.codecademy.com/learn/learn-sql
-
SQLite is a version of SQL that comes installed on mac! Try it out:
- In Terminal, type
sqlite3
to use SQLite. - Try adding a table with a command like
CREATE TABLE food (name TEXT, calories INTEGER);
- See that the table was created by typing
.tables
to see the list of all existing tables. - Try adding some data:
INSERT INTO food VALUES ("pizza", 500);
- See the data:
SELECT * from food;
Try creating tables and adding, updating, deleting, and querying data yourself!
- In SQLite, create the tables for an app similar to Twitter. Your database should be able to store: user information, tweets, and which users follow each other.
- Compare your table setup with another apprentice's.
- Add data to the tables
- Try writing queries that get data such as:
- All the tweets by a given user
- The 10 most recent tweets
- Use a join to get a user's info along with their tweets
- Find which user has the most followers
- Make up your own!
Make a cheat sheet of the SQL operations you know and what they do.