postgres Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database management system, other relational databases are MySQL, SQL Server, Oracle

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

good fit for storing related data, support good guarantees about data integrity, arguably one of the 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

top command

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

data stored in relations, a list of rows with information

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

What is a row?

A

a line in a table containing related information

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 JavaScript?

A

primary way of interacting with relational databases, unlike JavaScript it is declarative not imperative where we describe what we want and the programming environment comes up with its own plan for getting those results

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

select “specificColumn”

from “databaseTable”

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

select “specificColumn”
from “databaseTable”
where “x” = “y”

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

select “specificColumn”
from “databaseTable”
limit x

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 *

from “databaseTable”

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

select *
order by “x” desc (asc is default)
from “databaseTable”

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 “SQLTableName” (“property”

values (“propertyValue”)

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

What is a tuple?

A

in SQL a tuple is a list of values

17
Q

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

A

insert into “SQLTableName” (“property”
values (“propertyValue1”),
(“propertyValue2”),
(“propertyValue3”)

18
Q

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

A

returning *;
or
returning “rowname”;

19
Q

How do you update rows in a database table?

A

update “SQLTableName”

set “propertyName” = ‘newValue’

20
Q

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

A

If there is no where clause, then every row will be updated

21
Q

How do you delete rows from a database table?

A

delete from “SQLTableName”

where “propertyName” = ‘value’

22
Q

How do you accidentally delete all rows from a table?

A

exclude the where clause

23
Q

What is a foreign key?

A

a column referring to the same values in different tables

24
Q

How do you join two SQL tables?

A

select *
from “x”
join “y” using (“xy”)

25
Q

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

A

“x” as “y”

26
Q

What are some examples of aggregate functions?

A

sum, count, min, max,

27
Q

What is the purpose of a group by clause?

A

perform aggregate functions on groups of rows