PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

Relational database system.

SQLite, MySQL, Oracle, SQL Azure, Teradata

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 are commonly referred to as “SQL databases” because you usually do work with them using some variation of the SQL language.

If you are storing related data, then a relational database is probably a good first choice. A quality of many relational databases is that they support good guarantees about data integrity. They can store and modify data in a way that makes 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

sudo service postgresql status

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 is called a schema. A schema 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 a list of rows each having the same set of attributes.

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

What is a row?

A

You might visualize a database table as a sort of spreadsheet where each row is a record in that spreadsheet.

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

You may be familiar with imperative programming languages such as JavaScript, where you basically tell the JavaScript runtime what to do and how to do it.

QL is a declarative programming language. In declarative languages, programmers describe the results they want.

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 “column name”
from “table”

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

where “filter topic” = ‘category’

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

SQL does not have to be indented, but you should do it anyway for consistent style and therefore 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 #;

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

desc
(The default sort order of the results is ascending order)

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” (‘column name’)
values (‘value’)

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 list of values is referred to as a tuple.

17
Q

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

A

insert into “products” (“name”, “description”, “price”, “category”)

values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;

18
Q

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

A

returning *;

If you only want specific values back, you can use a comma-separated list of column names instead of an * asterisk.

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

it would update every row in the table!

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

if you don’t specify “where”

23
Q

What is a foreign key?

A

usually IDs

24
Q

How do you join two SQL tables?

A

select *
from “products”
join “suppliers” using (“supplierId”);

25
Q

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

A

select “p”.”name” as “product”,
“p”.”category”,
“s”.”name” as “supplier”,
“s”.”state”
from “products” as “p”
join “suppliers” as “s” using (“supplierId”);