postgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database. Often cited as the most advances open source database of its kind. Other relational databases are MySQL, SQL, and 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

Relational databases work around the SQL language so there’s a level of standardization. If you’re storing related data, it’s probably best to use a relational database. They also make data corruption as unlikely as possible.

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

You can check the top command to see if a PostgreSQL process is running, you can run a Postgres status command, or you can go to your database address and check as well

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

What is a database schema?

A

A database schema is a collection of tables A schema defines how the data in a relational database should be organized. Is defined up front

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

What is a table?

A

In terms of a relational database, tables are relations and contain a list of rows

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

What is a row?

A

A row is a section of a table and each row has the same set of attributes. Each row can be thought of as a record.

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

SQL is the language used to interact with relational databases. It’s different from JS in that it’s a declarative language. Where programmers describe the results they want as opposed to imperative programming languages where you tell the program what to do and how to do it.

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

you use the SELECT command and specify which column you want and then use the FROM keyword to specify which table it’s from

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

you use the WHERE clause and it needs to have an expression that evaluates to a boolean

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 than 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

you use the LIMIT keyword after your selection parameters… followed by the number of rows you want returned

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

with the * symbol

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

with the ORDER BY clause

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

The statement begins with the insert keyword

The table to insert into is specified in “ double quotes

The list of columns being inserted is wrapped in () parenthesis

The values being inserted are also wrapped in () in parenthesis in the same order as the columns they belong to… In SQL, a list of values is referred to as a tuple

Text values are wrapped in ‘ single quotes

Numeric values are represented with literal numbers (or decimals if applicable)

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 real values

17
Q

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

A

By including as many tuples as you want rows

18
Q

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

A

returning * clause

19
Q

How do you update rows in a database table?

A

update “products”

set “price” = 100;

20
Q

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

A

without a where clause, all values will be updated

21
Q

How do you delete rows from a database table?

A

delete from “products”
where “productId” = 24
returning *;

22
Q

How do you accidentally delete all rows from a table?

A

by not including a where clause

23
Q

What is a foreign key?

A

a foreign key is a key that is shared by 2 or more tables

24
Q

How do you join two SQL tables?

A

select statement followed by the specific columns you want from each table
from clause from the parent table
join the second table using the foreign key that they have in common

25
Q

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

A

you use the “as” clause to give it a temporary name… this is called aliasing

26
Q

What are some examples of aggregate functions?

A

sum, avg, count(*)

27
Q

What is the purpose of a group by clause?

A

The purpose of a “group by” clause is to perform aggregate functions on only a certain group of rows.