PostgreSQL Flashcards

1
Q

What are some advantages of learning a relational database?

A

Relation databases are used to store related data and can store and modify that data in a way that makes data corruption as unlikely as possible. They are also widely used - the most popular databases used in most businesses.

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 free, open-source relational database management system (RDBMS). It is its own database server, its own program.
We are simply using the database.
It has a robust feature set, standards compliance, and reliability. Relation databases are used to store related data and can store and modify that data in a way that makes data corruption as unlikely as possible.

Other 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 is one way to see if PostgreSQL is running?

A

The command sudo service postgresql status.

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

What is pgweb?

A

Pgweb is a web-based database browser for PostgreSQL, written in Go and works on OSX, Linux and Windows machines. Main idea behind using Go for backend development is to utilize ability of the compiler to produce zero-dependency binaries for multiple platforms. Pgweb was created as an attempt to build very simple and portable application to work with local or remote PostgreSQL databases.

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

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

A

SQL is the primary way of interacting with relational databases. It is how we CRUD data.

It’s a declarative programming language, different from imperative languages like JS because rather than telling it what to do and how to do it, the developer describes or declares the sought after results, and the database server dynamically generates a plan of action to get those results.

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

How do you retrieve specific columns from a database table?

A

Using the ‘select’ keyword followed by a comma delineated list of column names in double quotes.

Will also need to include the ‘from’ keyword and the table you’re retreiving from.
You can optionally add some filtering features with the ‘where’ clause or the ‘order by’ clause.

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

How do you filter rows based on some specific criteria?

A

Using the ‘where’ keyword followed by the filter column name, a comparison operator, and the value used to filter in single quotes.

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

What are the benefits of formatting your SQL?

A

Legibility and consistent style.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

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

A

Using the ‘limit’ keyword and a numerical value, not in quotes.

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

How do you retrieve all columns from a database table?

A

Using the ‘select’ keyword with an asterisk * (universal operator?)

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

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

A

Using the ‘order by’ clause. You can optionally add ‘desc’ to the end for descending order (ascending is default).

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

How do you add a row to a SQL table?

A

Using an insert statement followed by the name of the table and a comma delineated list of column names wrapped in parentheses, then below that, the values keyword followed by a comma delineated list of respective values in single quotes wrapped in parentheses. Optionally, you can add a returning keyword to the end to see the inserted data with the autogenerated column data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
Q

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

A

Entering a comma delineated list of tuples, each wrapped in its own set of parentheses

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

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

A

The returning keyword and * if you want all the column data, or a specified list of columns.

17
Q

How do you delete rows from a database table?

A

Using a ‘delete’ statement followed by the table name, and then a ‘where’ clause with an associated or identifying tuple.

18
Q

How do you accidentally delete all rows from a table?

A

By not including a ‘where’ clause.

19
Q

How do you delete rows from a database table?

A

Using a ‘delete’ statement followed by the table name, and then a ‘where’ clause with an associated or identifying tuple.

20
Q

How do you update rows in a database table?

A

Update keyword followed by the table name, then the ‘set’ keyword followed by the category or column and then the equal sign and then the values, then probably a ‘where’ clause indicating specificity.

21
Q

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

A

It gives you control over the rows you’re updating otherwise you will override the column in all of the rows.

22
Q

How do you accidentally delete all rows from a table?

A

By not including a where clause.

23
Q

What is a foreign key?

A

The reference Id/value in one table to data from another table, in which the foreign key is the primary key or primary ID.

24
Q

How do you join two SQL tables?

A

Using the ‘select’ keyword followed by the data you want using dot notation to join the table and column name where appropriate, then a ‘from’ keyword defining the starting point of your joined tables, then the ‘join’ clause including the second table name and the’ using’ keyword followed by related key or column.

25
Q

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

A

Using the as keyword in either the ‘select statements or in the from or join` clauses after the associated table names to assign aliases