postgresSL / SQL Flashcards

1
Q

Why do we use databases in Web development?

A

To store data to be quickly retrieved, esp when it’s complex data and needs to be organized
They can also be used by many users and it provides a central location

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

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database.

Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.

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

Good data integrity (rejects “bad” data) (see below)

A quality of many relational databases is that they support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible. This means that developers can set up their database to reject “bad” data and not worry about data being “half written”.

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

also, using the “sudo service postgresql status” command

using the “top” command and watching for it in the list of processes

“sudo” stands for “super user do”, aka an admin LOL

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

what command starts the postgres database?

A

sudo service postgresql start

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

what command stops the postgres database?

A

sudo service postgresql stop

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

what command checks postgrest status?

A

sudo service postgresql status

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

what does the pgweb command do?

A

it runs a server and lets you access from the browser, it queries your databases and gives you a GUI - graphical user interface, or webpage, to work in

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

What is a database schema?

A

a collection of relations (relations are like tables with rows & columns)

or, definition of all that describes your database

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

What is a table?

A

it has rows and columns for data, and in coding is called a relations

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

What is a row?

A

horizontal grid section with attributes in each column

like an object

a row is like an instance of a class

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

What is an attribute and what other names are used to describe them?

A

a column

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

what is a “primary key”

A

like an ID, basically

it uniquely identifies the row

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

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

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

How do you retrieve specific columns from a database table?

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

How do you filter rows based on some specific criteria?

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

What are the benefits of formatting your SQL?

A

readability, consistency

code is read many more times than it is written!

18
Q

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

A

< > = !=

19
Q

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

A

use the limit keyword

20
Q

How do you retrieve all columns from a database table?

A

use “*”

21
Q

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

A

type “order by”

22
Q

How do you add a row to a SQL table?

A
23
Q

What is a tuple?

A

a list of values in parentheses

24
Q

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

A

use a comma and add another tuple, e.g.,

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 *;

25
Q

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

A
26
Q

How do you update rows in a database table?

A

update “products”
set “price” = 100
where “productId” = 24;

27
Q

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

A

so you don’t delete ALL!

28
Q

How do you delete rows from a database table?

A

delete
from “products”
where “productId” = 24
returning *;

29
Q

How do you accidentally delete all rows from a table?

A

by not adding “where”

30
Q

What is a foreign key?

A

A key that is given by joining another table using the other table’s primary key

31
Q

How do you join two SQL tables?

A

using “join …. using … “

32
Q

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

A

use “as”

33
Q

how do you find the “key”

A

find the column that uniquely identifies each item

if you can’t find it just look in the “constraints” tab in the gui

34
Q

What are some examples of aggregate functions?

A

count() , sum(), total() …

35
Q

What is the purpose of a group by clause?

A

to group sth by a certain parameter
(can do it manually using other ways as leanred from previous exercises)

36
Q

What are JavaScript classes?

A
37
Q

When would you want to use a class?

A
38
Q

How do you declare a class?

A
39
Q

How do you inherit from another class?

A
40
Q

Why would you want to inherit from another class?

A