postgres/sql Flashcards

1
Q

Why do we use databases in Web development?

A

to store data and information

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 data management system and other alternatives include Oracle, MySQL

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

Ease of use, open source, flexibility

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

sudo service postgresql status

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

What is a database schema?

A

it shows how a data is organized within the database

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

What is a table?

A

rows and columns used to store data titles and the data itself

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

What is a row?

A

the horizontal part of the table

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

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

A

an attribute in postgresql is the column in the postgresql table it shows the information of the data type

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 (SQL) is a way to interact with databases and it is different from JavaScript you tell it how to do it while in SQL you ask what you want

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

by using the select clause
(ex. select “firstName”, “lastName”
from “table_name”)

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

by using the where clause
(ex. where “lastName” = ‘Lee’)

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

for readability purposes

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

= < > <= >= !=

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

by using the limit clause
(ex. limit 10;)

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

by using an *
(ex. select *
from “table_name”;)

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

by using the order by clause
(ex. order of “price”;)

17
Q

How do you add a row to a SQL table?

A

by using the insert into keyword
(ex. insert into “students” (“name”, “age”))

18
Q

What is a tuple?

A

the list of values

19
Q

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

A

by adding multiple tuples

20
Q

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

A

by using the returning keyword
(ex. returning *;)

21
Q

How do you update rows in a database table?

A

by using the update keyword
(ex. update “student”
set “name” = “Timothy Lee”
where “studentId” = 2;)

22
Q

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

A

So it knows which row to update

23
Q

How do you delete rows from a database table?

A

by using the delete keyword
(ex. delete from “student”
where “studentId” = 2;)

24
Q

How do you accidentally delete all rows from a table?

A

by not putting where to delete
(ex. delete from “student”;)

25
Q

What is a foreign key?

A

it is a primary key from a different table

26
Q

How do you join two SQL tables?

A

by using the join keyword
(ex. select “p”.”amount”, “c”.”firstName”,
from “payment” as “p”
join “customers” as “c” using (“customerId”)
)

27
Q

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

A

by using the as keyword
(ex. select g.name as genre
from genres as g)

28
Q

What are some examples of aggregate functions?

A

sum(), avg(), count(), min(), max(), total()

29
Q

What is the purpose of a group by clause?

A

so that the aggregate function is applied to only that group

30
Q

What are JavaScript classes?

A

classes are used to create objects that have properties and methods, they also provide a more structured way to define and create objects

31
Q

When would you want to use a class?

A
32
Q

How do you declare a class?

A

by using the class keyword
(ex.
class Shape {
constructor (area, circumference)
}
)

33
Q

How do you inherit from another class?

A

by using the extends keyword
(ex.
class Square extends Shape {
}
)

34
Q

Why would you want to inherit from another class?

A

so that you can reuse the code instead of writing it all over again

35
Q

How do you add methods and properties to a class?

A

by adding it within the class object using functions