PostgreSQL Flashcards

1
Q

Why do we use databases in Web development?

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

What is PostgreSQL and what are some alternative relational databases?

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

What are some advantages of learning a relational database?

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

What is one way to see if PostgreSQL is running?

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

What is a database schema?

A

A collection of tables is called a schema. A schema defines how the data in a relational database should be organized. It dictates how the table will be set up and how it will look.

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

What is a table?

A

A table is what relational databases store data in. They are also known as relations, but are more commonly referred to as tables.

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

What is a row?

A

A row is all the information about one entry or id of the table.

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

What is an attribute and what other names are used to describe them?

A

An attribute is something related to a row. Other names used to describe them are column, property, key, characteristic, etc.

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

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

A

Structured Query Language (SQL) is the primary way of interacting with relational databases and is a powerful way of retrieving, creating, and manipulating data in a relational database. It’s different from languages like JavaScript because it is a declarative programming language while languages like JavaScript are imperative programming languages.

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

How do you retrieve specific columns from a database table?

A

You must “select” the columns/properties/keys in a comma separated list.

select “column”,
“property”,
“key”

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

How do you filter rows based on some specific criteria?

A

After “select”ing “from” a table, use “where” followed by the criteria. The criteria will be in double quotes “ “ while the criteria value will be in single quotes ‘ ‘ if it is a string, while things like numbers and booleans will not be in quotes at all.

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

What are the benefits of formatting your SQL?

A

Formatted SQL makes code look more consistent and therefore increases readability.

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

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

A

=, !=, <, and >.

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

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

A

At the end of a “select” statement, use “limit” followed by the number of rows you want returned. The number should not be in quotes.

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

How do you retrieve all columns from a database table?

A

By using “select” with the universal operator *.

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

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

A

By using “order by” after select, from, where but before limit, followed by a column name (in double quotes “ “). After the column name, you can also include desc to sort in descending order since the default sort order of the results is in ascending order.

17
Q

How do you add a row to a SQL table?

A

By using an SQL “insert” statement.

insert into “table” (“column”, “attribute”, “property”, “key”)
values (‘value’, ‘value’, number, boolean);

18
Q

What is a tuple?

A

A list of values.

19
Q

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

A

By using an SQL “insert” statement but specifying multiple “tuples” of values, separated by commas.

20
Q

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

A

By including “returning” followed by what you want to get back about the row. It can be returning * to get back the full inserted row back from the database, including its auto-generates attribute(s), or, if you only want specific values back, you can use a comma-separated list of column names instead of an * asterisk.

21
Q

How do you update rows in a database table?

A

By using an SQL “update” statement.
update “table”
set “column” = number,
“column” = ‘string’,
“column” = ‘string’
where “column” = number;

22
Q

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

A

It is important because without a where clause, your update statements would update every row in the table.

23
Q

How do you delete rows from a database table?

A

By using an SQL “delete” statement.
delete
from “row”
where “column” = 24
returning *;

24
Q

How do you accidentally delete all rows from a table?

A

By using an SQL “delete” statement but forgetting to include a where clause.

25
Q

What is a foreign key?

A

It is a key that is from another table.

26
Q

How do you join two SQL tables?

A

By using an SQL join clause.

select “p”.”name” as “product”,
“p”.”category”,
“s”.”name” as “supplier”,
“s”.”state”
from “products” as “p”
join “suppliers” as “s” using (“supplierId”)
where “p”.”category” = ‘cleaning’
and “p”.”price” < 20;

27
Q

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

A

You can alias column names by using the as keyword.

28
Q

What are some examples of aggregate functions?

A

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

29
Q

What is the purpose of a group by clause?

A

When you want to separate rows into groups and perform aggregate functions on those groups of rows.