Postgres Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a free open-source relational database management system

PostgreSQL is a relational database system that is free and open source. Some alternatives are MySQL, SQL Server, 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

They’re the most widely used type of database.

They support good guarantees about data integrity.

They can store and modify data in a way that makes corruption as unlikely as possible.

They are good for storing related data. They can store and modify data in a way that makes data corruption as unlikely as possible. Also, they are arguably the most widely used kind of database.

Simple Model. Flat

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

by running ‘sudo service postgresql status’ command
By having a 2nd terminal open and running the top command to monitor the open processes.

sudo service postgresql status / top

  1. Use the terminal command sudo service postgresql status.
  2. Check use the terminal top command to see if postgres is running
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 in a database.

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 and columns that store data 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 an entry in a table and every row contains the same set of attributes

A single instance of a record within 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 programming language. Instead of telling the code what to do, you describe the results you want.

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

Start with the select keyword.

The select keyword is followed by a comma-separated list of column names, each surrounded by “double quotes”.

e.g: select “firstName”,
“lastName”

By using the select keyword follow by one or more column name wrapped in double quotes.

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

By using the where clause

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

For consistent style and readability

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

limit clause

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

asterisk

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

order by “column”; desc if you want it in descending order
Use the order by keyword followed by the column you want to order by in “double quotes.” order will be in ascending order by default - add desc keyword after “specified column” to sort in descending order.

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 statement insert into clause followed by the “table” then (column names separated by commas)

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

By using multiple tuples which are separated by commas but still follow the same order as the columns they belong to.

18
Q

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

A

using the returning keyword along with the star/asterisk

19
Q

How do you update rows in a database table?

A

update clause followed by name of table. then the set clause followed by the column that needs updating followed by an equal operator then the value of the desired update

20
Q

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

A

If a where clause is not used, the whole entire table is updated instead of just the targeted/desired data.

21
Q

How do you delete rows from a database table?

A

delete from clause followed by the table

22
Q

How do you accidentally delete all rows from a table?

A

By not specifying what to delete with the where clause

23
Q

What is a foreign key?

A

a key used to link two tables together

A column that links one table to another

24
Q

How do you join two SQL tables?

A

from clause followed by the table name and then the join clause followed by the table name as well and then the using keyword to specify the foreign key.

25
Q

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

A

By creating an Alias name with the as keyword

26
Q

What are some examples of aggregate functions?

A
max(): Finds max number
avg(): Finds average
count(*): Counts number of rows
min()
sum()
every()
look into JSON aggregate functions
27
Q

What is the purpose of a group by clause?

A

Separates rows into groups to perform aggregate functions.