postgres Flashcards
What is PostgreSQL and what are some alternative relational databases?
relational database management system.
alternative relational databases: SQLite, SQLserver, SQLoracle, mySQL
What are some advantages of learning a relational database?
it is widely used
What is one way to see if PostgreSQL is running?
by using ‘sudo service postgresql status’ in the terminal
What is a database schema?
Defines how the data in a relational database should be organized
schema defines the STRUCTURE
how you want to structure and store our data
What is a table?
A table is a list of rows each having the same set of attributes
attribute - same datatypes
What is a row?
having the same set of attributes
data in the table
What is SQL and how is it different from languages like JavaScript?
structured query language. a powerful way of retrieving, creating, and manipulating data
it’s a declarative programming language whereas JS is imperative
How do you retrieve specific columns from a database table?
using `select “columnName”
How do you filter rows based on some specific criteria?
where “columnName” = ‘thing you want’
What are the benefits of formatting your SQL?
helps to make the queries more readable and easy to understand
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?
using limit
How do you retrieve all columns from a database table?
using select *
How do you control the sort order of a result set?
order by ___ desc
How do you add a row to a SQL table?
insert into “ “ (“ “, “ “)
values (‘ ‘, ‘ ‘)
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
set another ( ) with values inside it
How do you get back the row being inserted into a table without a separate select statement?
by putting returning *
;
How do you delete rows from a database table?
delete from “ “
where “ “ =
returning *;
How do you accidentally delete all rows from a table?
when you just write delete from " "
without any where
clause
How do you update rows in a database table?
update “ “
set “ “ = ___ ,
“ “ = ____
where “ “ = ___;
Why is it important to include a where clause in your update statements?
because it can update every single row of that category if where is not included.
What is a foreign key?
Column’s value is one database is the SAME as another database’s so that you can associate it together
How do you join two SQL tables?
using select, from, join “ “ using (“ “)
How do you temporarily rename columns or tables in a SQL statement?
as “ “
What are some examples of aggregate functions?
max(), count(), avg(), sum()
What is the purpose of a group by clause?
when you want to separate rows into groups and perform aggregate functions on those groups of rows
organizes your result sets into buckets
aggregate function is applied to the groupby