Databases/postgreSQL Flashcards
What is PostgreSQL?
“Post Gress Queue El”
relational database management system
What are some alternative relational databases?
Examples: MySQL, Amazon Aurora, Google Fusion Tables, Oracle
What are some advantages of learning a relational database?
Most widely used type of database
Good for storing related data
Good for supporting data integrity
Portable skill
What is one way to see if PostgreSQL is running?
top
sudo service postgresql status
What is a relational database?
A digital database based on the relational model of data, where all data is represented in terms of tuples, grouped into relations)
**commonly referred to as “SQL databases” because you usually do work with them using some variation of the SQL language
What is a database schema?
A collection of tables, defines how the data in a relational database should be organized.
**Schema needs to be defined up front, server will make sure any data being written to database conforms to this schema
What is a table?
(AKA relations) a list of rows that each have the same set of attributes
What is a row?
Line of data with values for each attribute
What is SQL and how is it different from languages like JavaScript?
Structured Query Language - primary way of interacting with and managing relational databases (retrieving, creating, and manipulating data in a relational database)
**declarative - describe results wanted and environment comes up with how to get those results
How do you retrieve specific columns from a database table?
select statement:
select “columnName1”,
“columnName2”
from “tableName”;
How do you filter rows based on some specific criteria?
where (clause) “columnName” = ‘specificValue’;
What are the benefits of formatting your SQL?
Easier to read, easier to see what data is being requested
What are four comparison operators that can be used in a where clause?
, <=, =>, =, != (predicate to truthy or falsy)
How do you limit the number of rows returned in a result set?
limit # (clause) ;
How do you retrieve all columns from a database table?
select *
from “tableName”
How do you control the sort order of a result set?
order by “columnName”
Declarative (SQL, CSS, HTML) vs. imperative (JavaScript) programming language
imperative - tell what to do and how to do it
declarative - describe results wanted and environment comes up with how to get those results
How do you add a row to a SQL table?
**insert statement
insert into “tableName” (“columnName”, “columnName”)
values (‘value’, ‘value)
What is a tuple?
a list of values (‘value1’, ‘value2’)
finite ordered list
How do you add multiple rows to a SQL table at once?
listing more than one tuple (list of values) which are separated by a comma
How to you get back the row being inserted into a table without a separate select statement?
returning *
How do you update rows in a database table?
update “tableName”
set “columnName” = newValue
where “columnName” = oldValue;
Why is it important to include a where clause in your update statements?
So that it doesn’t update every single row and only targets specific rows
How do you delete rows from a database table?
delete from “tableName”
where “columnName” = ‘value’
returning *
How do you accidentally delete all rows from a table?
delete from “tableName”
**with no where clause
What is a foreign key?
values in one column from a column on a different table
How do you join two SQL tables?
select “tableName1”.”columnName1” as “aliasColumnName1”,
“tableName2”.”columnName2” as “aliasColumnName2”,
from “tableName1”
join “tableName2” using (“columnName”);
How do you temporarily rename columns or tables in a SQL statement?
as clause
What are some examples of aggregate functions?
max()
avg()
every()
bool_and()
What is the purpose of a group by clause?
To determine how the resulting table will output and which column it should be sorted/grouped by, how to group rows together