PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

It is a relational database system. Alternatives include: SQLite, MySQL

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

What is a database schema?

A

A database schema is a collection of tables

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

What is a row?

A

A row is a collection of related data

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

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

A

It is a declarative language like HTML, and CSS. Meaning: All we do is tell SQL what we want to happen and it forms the plan.

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

How do you retrieve specific columns from a database table?

A

You would retrieve it with: SELECT "columnName"

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

How do you filter rows based on some specific criteria?

A

You would use the WHERE keyword

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

What are the benefits of formatting your SQL?

A

Pure readability

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

You can use:
- =
- !=
- <
- >

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

You would use the LIMIT keyword (ex. LIMIT 5

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 would use the LIMIT keyword (ex. LIMIT 5)

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

You would retrieve it with: 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

One can order it with the keywords ORDER BY "columnName" (DESC/ASC)
Where if none are specified it defaults to ASC

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 (“attribute1”, …“attributeN”)
VALUES (“value1”, …“valueN”);
````

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

One would simply list more tuples

18
Q

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

A

One can use the RETURNING statement followed by an * or any attributes desired

19
Q

How do you update rows in a database table?

A

One would need to use the UPDATE keyword and then use SET to change the value (ex. `UPDATE artists

20
Q

How do you update rows in a database table?

A

One would need to use the UPDATE keyword and then use SET to change the value (ex. UPDATE artists SET name='example')

21
Q

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

A

So you can select what data is being updated as opposed to every row in the table

22
Q

What is a foreign key?

A

A key that is used to link values from one table with another (ie. they intersect)
If a value is a foreign key in a table then it references a primary key in another table.

23
Q

How do you join two SQL tables?

A

With the JOIN and USING keywords

24
Q

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

A

With the AS keyword

25
Q

What are some examples of aggregate functions?

A
  • COUNT()
  • MAX()
  • MIN()
  • SUM()
  • AVG()
26
Q

What is the purpose of a group by clause?

A

In order to group rows that we wish to report on