PostgreSQL + SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

a Relational Database Management System

uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads

MySQL, SQL, and Oracle SQL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some advantages of learning a relational database?

A

1) let you store relational data– data that connect to one another in some way
2) relational databases support good guarantees about data integrity - developers can set up their database to reject “bad” data and not worried about data being “half written”
3) most widely used kind of database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is one way to see if PostgreSQL is running?

A

1) by doing
sudo service postgresql status
to check its status

2) running top command
3) pgweb (the GUI will not work if postgreSQL is not running)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a database schema?

A

its a blueprint of how your data will look

a collection of tables

it defines how the data in a relational database should be organized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a table?

A

a table is where relational databases are stored

a table is a list of rows with the same set of attributes

ex: “customers” table could have “customerId” “firstName” “lastName” “email” “orderNumber”
ex: all students in a “students” table could have “firstName”, “lastName” and “dataOfBirthday” attributes

(attributes are referred to as columns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a row?

A

a row share the same set of attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you retrieve specific columns from a database table?

A

select keyword
list of the attribute name
from the name of the table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you filter rows based on some specific criteria?

A

where clause, attribute name, operator, condition

this expression evaluates to true of false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the benefits of formatting your SQL?

A

make your code more readable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are four comparison operators that can be used in a where clause?

A

=, , !=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you limit the number of rows returned in a result set?

A

limit follow by maximum number you want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you retrieve all columns from a database table?

A

by using asterisk *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you control the sort order of a result set?

A

order by clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is SQL and how is it different from languages like JavaScript?

A

SQL (similar to CSS and HTML) is a declarative programming language where programmers have to DESCRIBE the results they want and the programming environment (Web browser) comes up with its own plan for getting those results

relational databases interpret SQL and then DYNAMICALLY GENERATE A PLAN OF ACTION to perform the programmer’s commands as efficiently as possible

Whereas JavaScript is an imperative programming language where you tell the JavaScript runtime what to do and HOW TO DO IT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you add a row to a SQL table?

A

insert statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a tuple?

A

a list of values

17
Q

How do you add multiple rows to a SQL table at once?

A

you can specify more than one tuple of values by separating them with a comma

18
Q

How do you get back the row being inserted into a table without a separate select statement?

A

using the returning clause

returning *;
instead of * you can use a coma separated list of column names

19
Q

How do you update rows in a database table?

A

update statement

20
Q

Why is it important to include a where clause in your update statements?

A

including a where clause will target specific row, without it, it will update EVERY row in the table

21
Q

How do you delete rows from a database table?

A

delete statement with a where clause

22
Q

How do you accidentally delete all rows from a table?

A

by not specifying where / including a where clause

23
Q

What is a foreign key?

A

a column (a table identifier column) that is used to establish a link between the data in two tables

the column (aka foreign key) is used in another table (aka the foreign key table)

the VALUE from a foreign table that is used to link to another table??

24
Q

How do you join two SQL tables?

A

after SELECTing the table, use the JOIN statement to join another table

25
Q

How do you temporarily rename columns or tables in a SQL statement?

A

by calling the column (if you’re joining columns) follow by a period follow by the column name and an AS keyword and then the name you’re changing it to

26
Q

What are some examples of aggregate functions?

A

max(), min(), avg(), count(), min(), sum(), every()

27
Q

What is the purpose of a group by clause?

A

to separate rows into groups and perform aggregate functions on those groups of rows