postgres Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

relational database management system.
alternative relational databases: SQLite, SQLserver, SQLoracle, mySQL

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

it is widely used

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 using ‘sudo service postgresql status’ in the terminal

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

What is a database schema?

A

Defines how the data in a relational database should be organized

schema defines the STRUCTURE
how you want to structure and store our data

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

What is a table?

A

A table is a list of rows each having the same set of attributes
attribute - same datatypes

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

What is a row?

A

having the same set of attributes
data in the 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

structured query language. a powerful way of retrieving, creating, and manipulating data

it’s a declarative programming language whereas JS is imperative

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 `select “columnName”

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

where “columnName” = ‘thing you want’

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

helps to make the queries more readable and easy to 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

using limit

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

using 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

order by ___ 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 “ “ (“ “, “ “)
values (‘ ‘, ‘ ‘)

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

set another ( ) with values inside it

18
Q

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

A

by putting returning *;

19
Q

How do you delete rows from a database table?

A

delete from “ “
where “ “ =
returning *;

20
Q

How do you accidentally delete all rows from a table?

A

when you just write delete from " " without any where clause

21
Q

How do you update rows in a database table?

A

update “ “
set “ “ = ___ ,
“ “ = ____
where “ “ = ___;

22
Q

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

A

because it can update every single row of that category if where is not included.

23
Q

What is a foreign key?

A

Column’s value is one database is the SAME as another database’s so that you can associate it together

24
Q

How do you join two SQL tables?

A

using select, from, join “ “ using (“ “)

25
Q

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

A

as “ “

26
Q

What are some examples of aggregate functions?

A

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

27
Q

What is the purpose of a group by clause?

A

when you want to separate rows into groups and perform aggregate functions on those groups of rows
organizes your result sets into buckets
aggregate function is applied to the groupby