PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

powerful relational database management system

Redis MangoDB etc

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

a lot of databases use SQL languages / popular

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 -> it sets how the table should be structured

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

What is a table?

A

list of a row each having set of attribute

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

What is a row?

A

list of datas in table structured

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

primary way of interacting with relational databases (retrieving, creating, and
manipulating data)
Different from javascript -> imperative langue where programmer tell what to do and how to do
sql -> declarative -> program figures out and describe the results

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 “column”,
if more than one column. “ “
from “table”
(optional)
where “column” = ‘value’
order by “column” (optional) desc
limit number;

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 “ “ =, >,

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

retrieve the data easily

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

*

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 “column”
if descending order
order by “column” desc

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
sql = `insert into "table" ("column", "column")
         values ($1, $2)
returning *;
`
values = [value for $1, value for $2]

db
.query(sql, values)
numbers area automatically generated by app due to avoid duplicate 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

insert into “table” (“column”, “column)
values (‘1st’, ‘1st’)
(‘2nd’, ‘2nd’);

18
Q

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

A

using returning*

19
Q

How do you update rows in a database table?

A

all -> update “table”
set “column” = ‘new value’;
specific -> update “table”
set “column” = ‘new value’
where “column” = ‘existing value’;
multiple -> update “table”
set “column” = ‘new value’,
“column2” = ‘new value,
where “column” = ‘existing value’;

20
Q

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

A

if not, it would update all row values in the table

21
Q

How do you delete rows from a database table?

A

delete from “table”
where “column” = ‘value’;

delete from “table”
where “column” = ‘value’
and “column” , =, != ‘value’

22
Q

How do you accidentally delete all rows from a table?

A

when you don’t put where

23
Q

What is a foreign key?

A

just one column that links other table to the current table (mostly id)

24
Q

How do you join two SQL tables?

A

select*

from “table”
join “table2” using (“mainlyid”)

25
Q

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

A

select “column” as “newname”

26
Q

What are some examples of aggregate functions?

A

count, sum, max, min, avg

select \_\_\_("column")
from"table"
27
Q

What is the purpose of a group by clause?

A

the selected data gets grouped based on group by “column”