Week 9 Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a relational database system
Alternatives: MySQL, SQL Server by Microsoft, Oracle by Oracle Corporation
What are some advantages of learning a relational database?
It’s the most widely used kind of data base so the chances that you’ll run into it as a developer is high
It also can store and modify data in a way that makes data corruption as unlikely as possible
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
a collection of tables
describes the rules of how tables can be stored
it defines how the data in a relational database should be organized
What is a table?
a list of rows, each having the same set of attributes aka columns
ex: all students in a “students” table could have “firstName”, “lastName”, and “dateofBirth” attributes
What is a row?
A collection of attributes for a single record in the table
a record/single instance of data
What is SQL and how is it different from languages like JS?
SQL is a declarative language - aka you describe the results you want and the program comes up with its own plan for getting the results
JS is an imperative language – you tell js what to do and how to do it
How do you retrieve specific columns from a database table?
select “name of column” from “name of table”
How do you filter rows based on some specific criteria?
use “where” and the criteria
What are the benefits of formatting your SQL?
consistency and readability
What are four comparison operators that can be used in a where clause?
=, <, >, !=
How do you limit the number of rows returned in a result set?
limit with an integer
How do you retrieve all columns from a database table?
use * (asterisk)
How do you control the sort order of a result set?
you specify it with order by “column-name” … default is ascending order
How do you add a row to a SQL table?
insert into “tableName” (“col1”, “col2”, …)
values (‘val1’, ‘val2’, …)
column names are wrapped in “ “
values are wrapped in ‘ ‘
What is a tuple?
A list of values inside of parenthesis with each value wrapped in ‘ ‘
How do you add multiple rows to a SQL table at once?
You separate the tuples by commas
How do you get back the row being inserted into a table without a separate select statement?
use returning
- for all columns or comma-separated list of column names if you want specific ones
How do you update rows in a database table?
update “tableName”
set “column” = ‘value’
where “column” = ‘value’
ex:
update “products”
set “price” = 100
where “productId” = 24