PostgresQL/SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

It is a relational database. Alternative relational databases include MySQL, SQL Server by Microsoft and 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

Most widely used type of database. You can store related data easily

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

Run ‘sudo service postgresql status’ in the terminal. Can also check in your terminal by running the command ‘top’

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. A description of how the database should be structured

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

What is a table?

A

A list of rows with 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 set of related data describing one item

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

The primary way of interacting with relational databases. It is a declarative programming language where programmers describe the results they want rather than tell it exactly what to do and how to do it.

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

Using the select statement and a comma-separated list of column names, each wrapped in a pair of quotes, followed by the from clause specifying which table to grab the data from and ending with a semicolon.

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

Using the where clause. It needs to evaluate as true or false

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

It gives it a consistent style and it’s 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

=, , !=

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

Using the limit clause followed by the number you want to limit it by

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

By using *

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

Using the order by clause. It is defaulted to ascending, so if you want it descending, you must include ‘desc’ at the end.

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

Using the insert ‘keyword into statement’ followed by the name of the table in quotes and a list of columns individually in quotes being inserted wrapped in parentheses. The values clause and the values being inserted are also wrapped in parentheses in the same order as the columns.

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

What is a tuple?

A

A list of values

17
Q

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

A

Comma separated list of tuples.

18
Q

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

A

Using the returning clause.

19
Q

How do you update rows in a database table?

A

Using the ‘update’ statement followed by the table in quotes and the set clause reassigning the column to the new value. Include the where clause to target specific rows

20
Q

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

A

Otherwise you update the entire column.

21
Q

How do you delete rows from a database table?

A

Using the delete from statement followed by the table to be referenced to and a where clause to select the row/rows.

22
Q

How do you accidentally delete all rows from a table?

A

“Delete from ‘products’”

23
Q

What is a foreign key?

A

A column that specifically refers to values from another table - a shared attribute

24
Q

How do you join two SQL tables?

A

Using the join clause following the ‘from’ clause.Join tables ‘using’ the attribute to join them with.

25
Q

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

A

By using “as” after you select the table and column

26
Q

What are some examples of aggregate functions?

A

Max, sum, avg, count

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.