PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

It is a relational database that is popular.

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

You can learn other relational database just as fast due to similarities

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

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

tables are relations

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

What is a row?

A

data about columns

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 and declarative programming language much like HTML and CSS
(You tell it what to do)

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

Use select “columnName”

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

Use where “columnName” operator (=, >, < e.t.c) ‘value’

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

Better readability and looks clean

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

equal, not equal, greater than, less than (equal to)

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

Use limit value

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

Use select asterisk (*)

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

Use order by “columnName” desc (by default it is ascending)

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 “tableName” (“columnName”, …)

values (‘value’, …)

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

What is a tuple?

A

List of values

17
Q

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

A

add more values (‘value’, …)

separated by comma (much like select)

18
Q

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

A

add returning * at the end

19
Q

How do you delete rows from a database table?

A

delete from “tableName”
where “columnName” operator ‘value’
and “columnName” operator ‘value’
(Use and for when multiple things should be true)

20
Q

How do you accidentally delete all rows from a table?

A

when you simply do

delete from “tableName”

21
Q

What is a foreign key?

A

Basically a mutual column from two different tables

22
Q

How do you join two SQL tables?

A

join “tableName” using (“columnName”)

23
Q

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

A

Use alias using (as) then aliasName

24
Q

What are some examples of aggregate functions?

A

min(), max(), count(), avg()

25
Q

What is the purpose of a group by clause?

A

it literally groups them nicely