PostgreSQL/SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database. It is cited as the most advanced open-source and free relational database available. MySQL, SQL Server by Microsoft, and Oracle are some alternative relational databases.

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 developers work with relational databases a little bit and many other relational databases work off the same SQL language.

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. It defines how the data in a relational database should be organized.

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

What is a table?

A

Data stored in ‘relations’

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

What is a row?

A

A row is collection of attributes or a single record in a table

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

SQL is a declarative language like HTML and CSS whereas JavaScript is an imperative language. With SQL, we describe the results we want and the environment figures out how to provide us with the result

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

You use select followed by the column names in double quotes (separated by a comma if multiple)

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

You can use where “row” and an assignment operator like =, <, >, or != and the value. If the value is a string use single quotes

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 is more consistent and easier to read/understand

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

Use the limit keyword and the maximum number of rows you want returned

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

You can use the universal selector (*) after the select keyword
e.g. select *

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

A result set returns in ascending order by default. If you want it to be returned in descending order you would use the order by keywords, the column name in double quotes, followed by the desc keyword
e.g. order by “price” desc

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 into

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 being added to a SQL table

17
Q

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

A

You separate each set of values with a ,

- Recommended to put on new lines for clarity

18
Q

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

A

Use a returning statement

19
Q

How do you update rows in a database table?

A

With the update from keywords

20
Q

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

A

If you do not then it will update all of the items in a table

21
Q

How do you delete rows from a database table?

A

With the delete from keywords

22
Q

How do you accidentally delete all rows from a table?

A

Similar to update from, if you do not specify where then you can run into the issue of deleting everything

23
Q

What is a foreign key?

A

The shared data value between tables

24
Q

How do you join two SQL tables?

A

You first select the items you want to use from each table
Select which table you want as the base with from
Then using the join keyword and using keyword followed by the foreign key in parenthesis (can also have more items separated by a comma))

25
Q

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

A

You can alias them using the as keyword

26
Q

What are some examples of aggregate functions?

A

Max, min, sum, count

27
Q

What is the purpose of a group by clause?

A

To separate groups by rows so that we can perform aggregate functions on them