diff --git a/lessons/complex-sql-queries.md b/lessons/complex-sql-queries.md index e52794e..5c0b0ea 100644 --- a/lessons/complex-sql-queries.md +++ b/lessons/complex-sql-queries.md @@ -42,7 +42,7 @@ CREATE TABLE comments ( - The first two should look pretty familiar. The only new-ish thing is the user of the `TEXT` data type. This is basically a VARCHAR with no cap (or rather a very large cap.) It has some other small differences but for now just know it's uncapped text. - `user_id INT REFERENCES users(user_id)` is technically all you need to make a foreign key. The first part, `INT`, makes it known that this key will be stored as an integer. It then uses the `REFERENCES` key word to let PostgreSQL know that it is a foreign key. A foreign key is a field in one table that references the **primary** key of another table. In this case, a comment will reference the user_id in another table, the users table. The `users` part say it's reference the users table and the `(user_id)` is the name of the key in the other table. In this case, we called both user_id (which will probably happen somewhat frequently but not always) so they match but if we had called the user_id just id in the users table, we'd put `id` there. - `ON DELETE CASCADE` lets PostgreSQL know what to do if the user gets deleted. So if a user makes a comment on the message board and then deletes their account, what do you want it to do? If you omit the `ON DELETE CASCADE` part, it's the same as doing `ON DELETE NO ACTION` which means it'll just error and not let you delete the user until you've deleted all the comments first. You can also do `ON DELETE SET NULL` which means it'll make the user_id null on any comment that was made by that user. -- We've dne the same for board_id, just referencing the boards table instead of the users table. +- We've done the same for board_id, just referencing the boards table instead of the users table. Let's go ahead and put some dummy data in there. Copy / paste [this query] into your psql terminal. It may take a few minutes. @@ -55,7 +55,7 @@ SELECT comment_id, user_id, LEFT(comment, 20) AS preview FROM comments WHERE boa ``` - Two new things here. The `LEFT` function will return the first X characters of a string (as you can guess, RIGHT returns the last X charcters). We'r doing this because this hard to read otherwise in the command line. -- The `AS` keyword lets you rename how the string is projected. If we don't use AS here, the string will be returned under they key `left` which doesn't make sense. +- The `AS` keyword lets you rename how the string is projected. If we don't use AS here, the string will be returned under the key `left` which doesn't make sense. Okay so you'll get something back like this: diff --git a/lessons/intro-sql-databases.md b/lessons/intro-sql-databases.md index 52ac316..f0be1cf 100644 --- a/lessons/intro-sql-databases.md +++ b/lessons/intro-sql-databases.md @@ -44,6 +44,6 @@ All of these are commercial products. They're all fairly old products (my father ## PostgreSQL -This takes us to PostgreSQL (said "post-gress"). PostgreSQL is another wonderful open source database that continues to gain lots of marketshare and how some absolutely killer features to it. We'll get into those as we go but know it scales, it is reach with great features, and is a very popular. It has illustrious users such as Apple, Microsoft, Etsy, and many others. +This takes us to PostgreSQL (said "post-gress"). PostgreSQL is another wonderful open source database that continues to gain lots of marketshare and has some absolutely killer features to it. We'll get into those as we go but know it scales, it is reach with great features, and is a very popular. It has illustrious users such as Apple, Microsoft, Etsy, and many others. [turing]: https://stackoverflow.com/a/7580013 diff --git a/lessons/json-in-postgresql.md b/lessons/json-in-postgresql.md index f1a5db7..967405a 100644 --- a/lessons/json-in-postgresql.md +++ b/lessons/json-in-postgresql.md @@ -12,7 +12,7 @@ This course incorrectly chooses to use the `JSON` data type when it should have [For more info read this blog post about it][jsonb]. -## JSON +## JSONB Sometimes you have data that just doesn't have a nice schema to it. If you tried to fit it into a table database like PostgreSQL, you would end having very generic field names that would have to be interprepted by code or you'd end up with multiple tables to be able describe different schemas. This is one place where document based databases like MongoDB really shine; their schemaless database works really well in these situations.