Skip to content

Commit

Permalink
Update databases_and_sql.md
Browse files Browse the repository at this point in the history
  • Loading branch information
DevlinRocha authored Aug 9, 2024
1 parent ea7ab41 commit ae8373b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion databases/databases/databases_and_sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Once your database is set up and you've got empty tables to work with, you use S

<span id='command-parts'>Every CRUDdy command in SQL contains a few parts -- the action ("statement"), the table it should run on, and the conditions ("clauses")</span>. If you just do an action on a table without specifying conditions, it will apply to the whole database and you'll probably break something.

For "Destroy" queries, the classic mistake is typing `DELETE FROM users` without a `WHERE` clause, which removes all your users from the table. You probably needed to delete just one user, who you would specify based on some (hopefully unique) attribute like "name" or "id" as part of your condition clause, e.g. `DELETE FROM users WHERE users.id = 1`. You can do all kinds of common sense things like using `>`, `<`, `<=` etc. comparison operators to specify groups of rows to run commands on or logical operators like `AND`, `OR`, `NOT` etc to chain multiple clauses together, e.g. `DELETE FROM users WHERE id > 12 AND name = 'foo'`.
For "Destroy" queries, the classic mistake is typing `DELETE FROM users` without a `WHERE` clause, which removes all your users from the table. You probably needed to delete just one user, who you would specify based on some (hopefully unique) attribute like "name" or "id" as part of your condition clause, e.g. `DELETE FROM users WHERE users.id = 1`. You can do all kinds of common sense things, such as using comparison operators (`>`, `<`, `<=` etc.) to specify groups of rows to run commands on, or logical operators (`AND`, `OR`, `NOT` etc.) to chain multiple clauses together, e.g. `DELETE FROM users WHERE id > 12 AND name = 'foo'`.

"Create" queries use `INSERT INTO` and you'll need to specify which columns to insert stuff into and then which values to put in those columns, which looks something like `INSERT INTO users (name, email) VALUES ('foobar','[email protected]');`. This is one of the few queries that you don't need to be careful about which rows you've selected since you're actually just adding new ones into the table.

Expand Down

0 comments on commit ae8373b

Please sign in to comment.