postgres 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).

some altenratives are SQL server, MySQL, 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

A quality of many relational databases is that they support good guarantees about data integrity.
Relational databases are arguably the most widely used kind of database

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 tables is called a schema. A schema defines how the data in a relational database should be organized. In relational databases, you typically have to define your schema up front and the database server will make sure that any data being written to the database conforms to that schema.

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

What is a table?

A

relational databases store data in relations, commonly referred to as tables. A table is a list of rows each having the same set of attributes. columns are often referred to as attributes.

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

What is a row?

A

rows are the single record of data

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?
How do you retrieve specific columns from a database table?
How do you filter rows based on some specific criteria?
What are the benefits of formatting your SQL?
What are four comparison operators that can be used in a where clause?
How do you limit the number of rows returned in a result set?
How do you retrieve all columns from a database table?
How do you control the sort order of a result set?

A

Structured Query Language (SQL) is the primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database. SQL is a declarative language, not imperative. imperative you have to tell each step.

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

How do you filter rows based on some specific criteria?

A

select “attributeName”,

from “tableName”

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

how do you filter rows based on specific criteria?

A

select “attributes”,
from “tablename,
where “attribute” = ‘alvin’;

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

cleaner easier to read

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

= < > between

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

use the limit clause

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

select *

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

How do you add a row to a SQL table?

A

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

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

What is a tuple?

A

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

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

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

A

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

17
Q

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

A

returning *

18
Q

How do you update rows in a database table?

A

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

19
Q

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

A

it would update every row in the table!

20
Q

How do you delete rows from a database table?

A

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

21
Q

How do you accidentally delete all rows from a table?

A

delete from “products”;

22
Q

What is a foreign key?

A

column in a table that has values that are constrained to match another column in another table.

23
Q

How do you join two SQL tables?

A

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

24
Q

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

A
select "p"."name" as "product",
       "p"."category",
       "s"."name" as "supplier",
       "s"."state"
  from "products" as "p"
  join "suppliers" as "s" using ("supplierId");
25
Q

What are some examples of aggregate functions? convert a lot of values into a single value.

A

sum
count
avg

26
Q

What is the purpose of a group by clause?

A

you want to separate rows into groups and perform aggregate functions on those groups of rows