Databases Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

An open-source relational database.

mySql / Oracle / SQL Server

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

So much work of a developer involves things that have relationships so RDB is a perfect tool

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

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

What is a table?

A

A table holds records that have the same attributes

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

What is a row?

A

A single 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

Structured Query language, used to interact with a database.
It’s declarative, you tell it what to do but not how to do it as opposed to JS which is imperative, you tell it how to do things

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 “col1”, “col2”

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 “col” = something

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

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

A

limit num;

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

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

A

order by “col”, ascending default or desc

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

How do you add a row to a SQL table?

A

insert into “table” (“col1”, “col2”)

values (“val1”, “val2”)

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

What is a tuple?

A

list of values

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

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

A

insert into “table” (“col1”, “col2”)
values (“val1”, “val2”),
(“val1”, “val2”)

17
Q

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

A

returning *

18
Q

How do you update rows in a database table?

A

update “table”
set “col” = newVal
where “col” = 24;

19
Q

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

A

if not, you are updating everything

20
Q

How do you delete rows from a database table?

A

delete from “table”

where “col” = 24

21
Q

How do you accidentally delete all rows from a table?

A

delete from “table”

22
Q

What is a foreign key?

A

one column that links the one table to another table.

23
Q

How do you join two SQL tables?

A

select “col”
from “table”
joining “table2” using (“col”)

24
Q

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

A

as “newName”

25
Q

What are some examples of aggregate functions?

A

sum, count, min, max

26
Q

What is the purpose of a group by clause?

A

Since the aggregate functions does something on all the rows, sometimes we want to combine that for specific groups separately