Schema
DatabaseSchema: The setup information for your database is stored in a special file called the “Schema”, and this is updated whenever you make changes to the structure of your database. Think of the schema as saying “here’s our database and it’s got a couple tables. The first table is ‘users’ and it’s got columns for ‘ID’ (which is an integer), ‘name’ (which is a bunch of characters), ‘email’ (which is a bunch of characters)
Indexes
CREATE INDEXES
Create indexes, which basically do all the hard work of sorting your table ahead of time, for columns that you’ll likely be using to search on later (like username)… it will make your database much faster.
Tips
- SQL likes semicolons at the end of lines and using single quotes
'
instead of double quotes"
.
Statement structure
Every CRUD command in SQL contains a few parts
The action statement
, the table
it should run on, and theclauses
.
// 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 example, to update a row in a table
UPDATE usersSET name='barfoo', email='bar@foo.com'WHERE email='foo@bar.com';