PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A
  • an open source relational database management system

- others are MySQL, oracle, sql server, sqlite

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

get to learn the widely used SQL language and relational database, also can store related data with data integrity

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’ in the terminal, then see if it says ‘online’

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 which defines how data in a relational database should be organized

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

What is a table?

A

a list of rows of stored data with 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

a horizontal line of data or single instance of a 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
  • a declarative programming language which interacts with relational databases
  • SQL is declarative, so you tell it what you want to do, but not how to do it, while JavaScript 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

use ‘select’ followed by column name in double quotes

ex. select “name”

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’, followed by name of row, comparison operator, name of cell to filter by in single quotes
ex. where “category” = ‘cleaning’;

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

consistency and 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’ followed by number of rows you want returned

ex. limit 1

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 * (asterisk)

from “tableName”;

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

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” (“rowName”,)
values (‘data’,)
ex.
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);

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 (wrapped in parenthesis)

17
Q

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

A

add another tuple in parenthesis after 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 “columnName” = ‘value’
where {expression} ex. “columnName” = ‘value’

20
Q

Why use where clause in update statements?

A

so you don’t update every single row in the table

21
Q

How do you delete rows from a database table?

A
delete from "tableName"
 where {conditional}
ex. delete from "products"
 where "productId" = 24
returning *;
22
Q

How do you accidentally delete all rows from a table?

A

delete from “tableName”

no where

23
Q

begin, commit, rollback

A

begin - don’t do the transaction yet
(then do the update or delete)
commit- finish the transaction
rollback - don’t want to commit, but want to end transaction

24
Q

What is a foreign key?

A

column which refers to a column in another table

25
Q

How do you join two SQL tables?

A
join "tableName" using ("columnName")
ex.
select *
  from "products"
  join "suppliers" using ("supplierId");
26
Q

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

A

rename column:
{keyword} “tableName”.”columnName” as “renamedColumn”

rename: table
{keyword} “tableName” as “renamedTable”

27
Q

What are some examples of aggregate functions?

A

max() avg() count() min() sum() every()

28
Q

What is the purpose of a ‘group by’ clause?

A

to group rows together into one row based on values of a specific column