PostreSQL Flashcards

1
Q

Why do we use databases in Web development?

A

It is quicker to query, organize, get access to data from a database. Store a lot of information. Data less likely to be stolen or corrupted, can be accessed by many computers/phones by many users.

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

An open source relational database. microsoft SQL server, MySQL, SQLite.

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

using the top command.
sudo service postgresql status.
sudo = super user do.

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

pgweb

A

pgweb queries your postgres database and visualizing it for you.

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

What is a database schema?

A

A collection of tables

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

What is a table?

A

A table is a list of rows each having the same set of attributes.
every row in a table should have the same columns.

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

What is a row?

A

an object, an instance of the data, a data point,
A row is a single set of data with all columns that describe pieces of the data.

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

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

A

Attributes are commonly referred to as columns. Keys, properties.

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

Structured Query Language, SQL is a declarative programming language which means you tell it the results you want, not what to do, as opposed to JavaScript which is an imperative programming language.

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

by using the select keyword followed by the column names in double quotes separated by commas.

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

by using the where keyword followed by the column name in double quotes, and then a comparison to the value in single quotes. an expression.

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

SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.

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

using the limit keyword followed by a number where the number is the max number of rows to be returned.

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

the select keyword followed by *. the * is not surrounded by any type of quotes

17
Q

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

A

using the order by keyword. This will sort it in ascending order, use the desc keyword to sort by descending order.

18
Q

How do you add a row to a SQL table?

A

using the insert keyword followed by into followed by the table you want to insert into in double quotes, followed by the parenthesis with the column inside quotes inside the parenthesis. then on the next line the keyword values followed by parenthesis and the values inside with single quotes if a string.
insert into “actors” (“firstName”, “lastName”)
values (‘Henry’, ‘Ding’)
returning *;

19
Q

What is a tuple?

A

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

20
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.

21
Q

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

A

In PostgreSQL it’s possible to get the full inserted row back from the database, including its auto-generated attribute(s), like a productId. This is done with a returning clause. Otherwise, it would be necessary to make a separate query to the database just to get the auto-generated attributes.

22
Q

How do you update rows in a database table?

A

update “tablename”
set “columnname” = ‘new value’
where “columnname” = ‘value’

23
Q

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

A

To make sure you only update the specific row you want and not everything.

24
Q

How do you delete rows from a database table?

A

delete
from “tablename”
where “columnname” = ‘value’

25
Q

How do you accidentally delete all rows from a table?

A

delete
from “tablename”

26
Q

What is a foreign key?

A

A foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data in two tables to control the data that can be stored in the foreign key table. A foreign key references other tables’s primary keys.

27
Q

How do you join two SQL tables?

A

using the join keyword and the using keyword

28
Q

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

A

select “addresses”.”line1” as “address”
will rename line1 to address.

29
Q

What are some examples of aggregate functions?

A

count(), sum(), min(), max(), every()

30
Q

What is the purpose of a group by clause?

A

the GROUP BY clause divides a table into sets.