Databases/postgreSQL Flashcards

1
Q

What is PostgreSQL?

A

“Post Gress Queue El”

relational database management system

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

What are some alternative relational databases?

A

Examples: MySQL, Amazon Aurora, Google Fusion Tables, Oracle

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

What are some advantages of learning a relational database?

A

Most widely used type of database
Good for storing related data
Good for supporting data integrity
Portable skill

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

What is one way to see if PostgreSQL is running?

A

top

sudo service postgresql status

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

What is a relational database?

A

A digital database based on the relational model of data, where all data is represented in terms of tuples, grouped into relations)
**commonly referred to as “SQL databases” because you usually do work with them using some variation of the SQL language

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

What is a database schema?

A

A collection of tables, defines how the data in a relational database should be organized.
**Schema needs to be defined up front, server will make sure any data being written to database conforms to this schema

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

What is a table?

A

(AKA relations) a list of rows that each have the same set of attributes

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

What is a row?

A

Line of data with values for each attribute

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

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

A

Structured Query Language - primary way of interacting with and managing relational databases (retrieving, creating, and manipulating data in a relational database)
**declarative - describe results wanted and environment comes up with how to get those results

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

How do you retrieve specific columns from a database table?

A

select statement:

select “columnName1”,
“columnName2”
from “tableName”;

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

How do you filter rows based on some specific criteria?

A

where (clause) “columnName” = ‘specificValue’;

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

What are the benefits of formatting your SQL?

A

Easier to read, easier to see what data is being requested

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

What are four comparison operators that can be used in a where clause?

A

, <=, =>, =, != (predicate to truthy or falsy)

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

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

A

limit # (clause) ;

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

How do you retrieve all columns from a database table?

A

select *

from “tableName”

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

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

A

order by “columnName”

17
Q

Declarative (SQL, CSS, HTML) vs. imperative (JavaScript) programming language

A

imperative - tell what to do and how to do it

declarative - describe results wanted and environment comes up with how to get those results

18
Q

How do you add a row to a SQL table?

A

**insert statement
insert into “tableName” (“columnName”, “columnName”)
values (‘value’, ‘value)

19
Q

What is a tuple?

A

a list of values (‘value1’, ‘value2’)

finite ordered list

20
Q

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

A

listing more than one tuple (list of values) which are separated by a comma

21
Q

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

A

returning *

22
Q

How do you update rows in a database table?

A

update “tableName”
set “columnName” = newValue
where “columnName” = oldValue;

23
Q

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

A

So that it doesn’t update every single row and only targets specific rows

24
Q

How do you delete rows from a database table?

A

delete from “tableName”
where “columnName” = ‘value’
returning *

25
Q

How do you accidentally delete all rows from a table?

A

delete from “tableName”

**with no where clause

26
Q

What is a foreign key?

A

values in one column from a column on a different table

27
Q

How do you join two SQL tables?

A

select “tableName1”.”columnName1” as “aliasColumnName1”,
“tableName2”.”columnName2” as “aliasColumnName2”,
from “tableName1”
join “tableName2” using (“columnName”);

28
Q

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

A

as clause

29
Q

What are some examples of aggregate functions?

A

max()
avg()
every()
bool_and()

30
Q

What is the purpose of a group by clause?

A

To determine how the resulting table will output and which column it should be sorted/grouped by, how to group rows together