PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS). It is often cited as the most advanced open source database of its kind and is well-liked by the developer community for its robust feature set, standards compliance, and reliability.

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
2
Q

What are some advantages of learning a relational database?

A

Many problem domains can be modeled well using a relational database. If you are storing related data, then a relational database is probably a good first choice!

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.

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

A collection of data-tables is called a schema.

A plan for your data that is has to follow.

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

What is a table?

A

A table is a list of rows each having 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 single horizontal entry in the database with a set of attributes.

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

Structured Query Language (SQL) is a declarative programming language to interact with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database.

Declarative programming language like HTML and CSS.

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

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

Makes it easier to debug.

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

< , >, =, and !=.

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

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

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

In SQL, a list of values is referred to as a tuple.

17
Q

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

A

Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas.

18
Q

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

A

returning *;

  • is short for all columns.

If you only want specific values back, you can use a comma-separated list of column names instead of an * asterisk.

19
Q

How do you update rows in a database table?

A

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

20
Q

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

A

To target specific rows to be updated.

21
Q

How do you delete rows from a database table?

A

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

22
Q

How do you accidentally delete all rows from a table?

A

You don’t specify “where”.

23
Q

What is a foreign key?

A

A column that links a table to another table.

24
Q

How do you join two SQL tables?

A

select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);

25
Q

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

A

select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);

26
Q

What are some examples of aggregate functions?

A

max( )
Ex:
select max(“price”) as “highestPrice”
from “products”;

avg( )
Ex:
select avg(“price”) as “averagePrice”
from “products”;

count( )
Ex:
select count(*) as “totalProducts”
from “products”;

min( )
sum( )
every( )

27
Q

What is the purpose of a group by clause?

A

To separate rows into groups and perform aggregate functions on those groups of rows.

Ex:
select "category",
       avg("price") as "averagePrice"
  from "products"
 group by "category";
28
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

29
Q

How do you handle the fulfillment of a Promise?

A

then( )

result.then(value => {
console.log(value);
});

30
Q

How do you handle the rejection of a Promise?

A

catch( )

result.catch(error => {
console.log(error.message);
});