PostgreSQL/SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

Open source relational database server

Other databases: SQLite, SQL Server, Oracle SQL

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

Great if you are storing related data. Less likelihood of data corruption. Most importantly: you will use it as a developer.

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

Dictates how data 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

Organized rows that have the same set of attributes. Overall, a place where data can be stored

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

What is a row?

A

One 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

Its a declarative language meaning you tell what you want and the language will interpret it. On the other hand, JS is imperative meaning you have to tell it exactly what you want it to do.

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

select “column”

from “table”;

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 clause “column” = ‘data’

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

SQL can get very complex. Structuring it will make it 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

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

*

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/asc

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 “table” (“column”, “column”)

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

What is a tuple?

A

Specific ordered list with paranthesis

17
Q

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

A

values (‘data’, ‘data’) separated by comma

18
Q

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

A

returning clause

19
Q

How do you update rows in a database table?

A

update “table”
set “column” = ‘data’
where “column” = ‘data’

20
Q

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

A

So you don’t update all the rows

21
Q

How do you delete rows from a database table?

A

delete from “table”

where “column” = ‘data’

22
Q

How do you accidentally delete all rows from a table?

A

delete from “table” with no other clauses

23
Q

What is a foreign key?

A

Columns that refer to another column in a different table. Data should match.

24
Q

How do you join two SQL tables?

A

join “table” using (“column”)

25
Q

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

A

as keyword which also refers to alias

26
Q

What are some examples of aggregate functions?

A

average, max, min, sum, amount

27
Q

What is the purpose of a group by clause?

A

Separate rows by groups