postgresQL Flashcards

1
Q

What is postgreSQL and what are some alternative relational databases?

A

open source relational database management system

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

most apps use data

easier to work with data that is related

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

top command in CLI

sudo service postgresql status command in CLI

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

What is a database schema?

A

a collection of tables

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 a list of rows each having the same set of attributes(aka columns)

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

What is a row?

A

each row is a single record of data in the table

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

what is SQL and how is it different from languages like JS?

A

sql is a language used to interact with relational databases

sql is declarative language rather than imperative like JS

you describe the result you want rather than what and how to do it like with JS

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

How do you retrieve specific columns from a database table?

A

use the “select” keyword and the string version of the columns in double quotes you wish to see separated by commas

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

How do you filter rows based on some specific criteria?

A

use the “where” statement

“columnName” operator (‘dataValue’)

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

What are the benefits of formatting your SQL?

A

readability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

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

A

limit clause followed by num value

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

How do you retrieve all columns from a database table?

A

select *

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

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

A

order by “columnName” desc/asc

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 into “table” (“columnName”, “columnName)
values (‘firstName’, ‘lastName’)
returning *;

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 in sql

17
Q

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

A

multiple tuple rows with commas separating the tuples

18
Q

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

A

returning *;

19
Q

How do you update rows in a database table?

A

using the “update”, “set”, and “where” keywords

20
Q

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

A

So that the code knows what row needs to be updated

21
Q

how do you delete rows from a database table?

A

using the clause “delete from” “table name” and “where”

22
Q

How do you accidentally delete all rows from a table?

A

delete from “table”;

23
Q

What does ACID stand for as it pertains to transactions?

A

Atomicity - all changes to data are performed as if they are a single operation. All changes are performed or none are

Consistency - data is in a consistent state when a transaction starts and when it ends

Isolation - the intermediate state of a transaction is invisible to other transactions

Durability - after successful transaction completes, changes to data persist and are not undone, event in the event of a system failure.

24
Q

3 commands to use with transactions

“transactions help with manipulating databases in a safe mode”

A

begin
commit
rollback

25
Q

what is a foreign key?

A

a column title that links data from another table to that table

column values need to be the same

26
Q

How do you join two sql tables?

A

select *
from “table”
join “table2” using (“foreign key from table 1”);

27
Q

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

A

using aliasing with the “as” keyword

doesn’t alter the name permanently

28
Q

What are some examples of aggregate functions?

A
max ( )
avg ( )
count ( )
sum ( )
min ( )
every ( )
29
Q

What is the purpose of a “group by” clause?

A

to sub-divide rows in a result set into groups and then perform the aggregate on each group