PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

o Open source Relational Database Management System (RDBMS)

o Alternative RDBMS include:
Proprietary (pay money to use) - Oracle
Open Source (like postgres) - MySQL

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

o Widely used
o They support good guarantees about data integrity
o Store and modify data in a way that makes data corruption unlikely
o Many relational databases are driven by almost the same language

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

o sudo service postgresql status

o top

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

What is a database schema?

A

o Rules for how a data gets stored

o Collection of tables & their structure

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

What is a table?

A

o Data stored in relations

o A list of rows that have 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

o A distinct record in a table

o A list of attributes and every row in the table has the same attributes

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

o Structured Query Language (SQL) – primary way of interacting with relational databases (by retrieving, creating and manipulating data).

o SQL is a declarative programming language (unlike JS which is imperative)

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 “attributeName”

from “tableName”

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 “attributeName” = ‘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

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

order by

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” (“attributeName”, . . .)

values (‘value’, ‘value’, . . . );

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 values (one line of values is “one tuple”)

17
Q

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

A

values (‘value’, ‘value’, . . . ),
values (‘value’, ‘value’, . . . )

(You add multiple tuples separated by a comma)

18
Q

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

A

returning

19
Q

How do you update rows in a database table?

A

update “tableName”

set “attributeName” = ‘newValue’;

20
Q

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

A

To target specific rows

21
Q

How do you delete rows from a database table?

A

delete from “tableName”

where “attributeName” = ‘value’

22
Q

How do you accidentally delete all rows from a table?

A

If you only write ‘delete from “tableName”’ WITHOUT A WHERE CLAUSE

23
Q

What is a foreign key?

A

A column present in one or more tables that links those tables together

24
Q

How do you join two SQL tables?

A

join “tableName” using (“foreignkey”)

25
Q

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

A

“columnOrTableName” as “newName”

26
Q

What are some examples of aggregate functions?

A
o	max()
o	avg()
o	count()
o	min()
o	sum()
o	every()
27
Q

What is the purpose of a group by clause?

A

To separate rows into groups based on a criteria