PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

relational database management system that often use some variation of a SQL language (Structured Query Language)

Alternatives: SQLite, mySQL, SQL server, 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

It’s widely used,
Support good guarantees about data integrity

Uses SQL language (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

sudo service postgresql status

top

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

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

list of rows each having the same set of attributes (columns)

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

What is a row?

A

Refers to a data in a table that has the same set of attributes/columns as the other rows

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

It is a declarative language (declare things and program makes it happen from its predetermined rules

Languages like JS are 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

select “columnName”,

“columnName2”, etc

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

Using the ‘where’ clause

e.g.
where “column” != ‘value’

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 helps with 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?

A

‘limit’ keyword

e.g.
limit 10;

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

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 “column”

default order is ascending

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” (…columns)

value (…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

have multiple tuples of values

18
Q

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

A

returning *;

19
Q

How do you update rows in a database table?

A

update “table”
set “column” = ‘value’
where condition(s)

*where clause is important!

20
Q

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

A

If there is no where clause, it will update the entire table

21
Q

How do you delete rows from a database table?

A
delete from "table"
where condition(s)
22
Q

How do you accidentally delete all rows from a table?

A

Using delete from without having a where clause

23
Q

What is a foreign key?

A

A shared column/attribute between tables that links/relates one set of data in a table to another

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

using as

join “table” using (“column”) as “newName”

select “column” as “newName”

26
Q

What are some examples of aggregate functions?

A

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

27
Q

What is the purpose of a group by clause?

A

Collapse/group data into a single row