PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

relational DB mgmt system
RDBMS

MySQL
SQL Server for MS
Oracle

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

short answer: widely used and very powerful

long answer:
once you learn one, you’ve learned them all except for nuances

they support good guarantees about data integrity; minimize data corruption

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

shortcut: can just run start command again and it won’t do anythin

sudo = (super user do) keyword in terminal that elevates your privileges

service = control a bg service

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

pgweb

A

a TOOL to VISUALIZE our DB
**this is not your server

How to access:

In the terminal that was running $top, launch the pgweb PostgreSQL database client by typing $pgweb and pressing enter. You can stop pgweb at any time by pressing $Ctrl + C.

Visit http://localhost:8081 in your web browser. The upper left corner of the UI should say dev.

**MUST STOP SERVER CTRL + C

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

psql -c ‘\l’

A

psql = logs into DB (can be used alone)

-c = command

’ \l ‘ = command in a string, [backslash l ] means list

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

why PostgreSQL?

A

works will with Node and has built in functionality, esp for array and object

a lot of ppl with Node backend use postgreSQL

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

What is a database schema?

A

collection of tables

the instructions to build the tables

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

What is a table?

A

data stored in relations

list of rows w/ same set of attributes (columns)

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

What is a row?

A

a record

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

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

A

how to interact with DB’s
declarative like HTML and CSS - you tell it what you want and it will give it back to you (order may change) via its own interpretation

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

How do you retrieve specific columns from a database table?

A

select “columnName”

from “tableName”

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

How do you filter rows based on some specific criteria?

A

where “condition” = ‘keyword’

use logical comparison operators

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

What are the benefits of formatting your SQL?

A

cleaner, minimize mistakes, easy to maintain

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

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

A

limit #ofrows

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

How do you retrieve all columns from a database table?

A

select * (wildcard selector)

17
Q

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

A

order by

18
Q

How do you add a row to a SQL table?

A

insert into “tableName” (“columnName”, “columnName”)

values

18
Q

How do you add a row to a SQL table?

A

insert into “tableName” (“columnName”, “columnName”)

values. (‘value’, ‘value’)

19
Q

What is a tuple?

A

a list of values

20
Q

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

A

use commas between value rows

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;

21
Q

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

A

returning *;

^^ use this as last line

22
Q

How do you update rows in a database table?

A

update “tableName”
set “columnName” = ‘value’
where “columnName” = ‘value’;

23
Q

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

A

otherwise you could update all rows the whole table and cannot undo it

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

if you don’t add where

26
Q

What is a foreign key?

A

common key btwn tables

27
Q

How do you join two SQL tables?

A

join “tableName” using (“columnName”)

28
Q

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

A

alias

“as”

29
Q

What are some examples of aggregate functions?

A

max
min
count
sum

30
Q

What is the purpose of a group by clause?

A

separate rows into groups and perform aggregate functions on them (instead of each row)