PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

A relational database; MySQL, SQL Server, Oracle

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

What is a database schema?

A

All of the tables in a database

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

What is a table?

A

Specifies each attribute the rows should have

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

What is a row?

A

A single object in the table

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 a language used to retrieve, create, and manipulate data in a relational database. It differs from JavaScript in that is a declarative programming language, so the programmer describes the results they want and the programming environment comes up with its own plan for getting 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

With the SELECT keyword, column names enclosed with double quotes and separated by commas.

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

With a WHERE keyword, followed by a column you wanted to filter by enclosed in double quotes, then a comparison operator, then the value to compare against.

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

To enhance readability for other developers.

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

With the LIMIT keyword, followed by an integer.

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

By replacing the list of column names with an asterisk.

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

With an ORDER BY keyword, followed by the column you want to sort by enclosed in double quotes, and then an optional DESC keyword to reverse sort order.

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

With an insert statement;
Insert into keywords followed by table name enclosed in double quotes, followed by an attribute list enclosed in parentheses. Then the values keyword followed any tuples.

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

What is a tuple?

A

A tuple is a set of values for one row.

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

By adding multiple tuples after the values keyword in an insert statement, with commas in between.

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

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

A

With the returning keyword followed by an asterisk.

17
Q

How do you update rows in a database table?

A

With an update statement;
Update keyword, followed by table name enclosed in double-quotes, then the set keyword followed by the name of the attribute to be updated, then the assignment operator and whatever you are going to replace the value with.

18
Q

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

A

Because it will update every row in the table if you leave it out.

19
Q

How do you delete rows from a database table?

A

With a delete statement;
Delete from keywords, followed by the table name enclosed in double-quotes, then the where keyword followed by the name of the attribute to be checked, followed by a conditional operator and the value you are checking against.

20
Q

How do you accidentally delete all rows from a table?

A

By not specifying a where clause in your delete statement.

21
Q

What is a foreign key?

A

An attribute shared by two tables that contain the same value.

22
Q

How do you join two SQL tables?

A

By adding a join clause to a select statement;
‘join’ keyword followed by the name of the table to be joined enclosed in double-quotes, then the ‘using’ keyword followed by the attribute which the tables are linked by, enclosed in double-quotes and wrapped with parentheses.

select “products”
join “suppliers” using (“supplierId”)

23
Q

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

A

With aliasing;
We do this by adding an ‘as’ keyword after the attribute name in the select statement, followed by the alias wrapped in double-quotes.

select “products”.”name” as “product”

24
Q

What are some examples of aggregate functions?

A

max ( ), min( ), sum( ), avg( ), count( )

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