PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

open source object-relational database management system; mySQL, Oracle, Microsoft SQL server

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

Relational databases are arguably the most widely used kind of database. Many web developers work with a relational database at least a little bit during their career

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

command 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

a collection of tables that 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

a list of rows each having the same set of attributes;a database table is sort of like a spreadsheet where each row is a record in that spreadsheet

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

What is a row?

A

single structured data item 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

primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database; JavaScript is imperative and SQL is declarative

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”

from “tableName”;

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” = ‘specific description’

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

consistent style 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 set?

A

limit number; limit clause always comes last

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 *

from “tableName”

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 clause ; default it ascending order; if specified can use descending order; order by “whatever” 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 “tableName”(“columnName”)

values (‘columnValue’);

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

What is a tuple?

A

the list of values being inserted in parenthesis

17
Q

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

A

insert into “tableName”(“columnName”)
values (‘this’),
(‘that’)

18
Q

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

A

use returning clause;
insert into “tableName”(“columnName”)
values (‘columnValue’)
returning *;

19
Q

How do you update rows in a database table?

A

update “tableName”
set “columnName” = ‘new value’
where “columnName” = ‘value’

20
Q

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

A

to update specific statments at target specified in where clause

21
Q

How do you delete rows from a database table?

A

delete from “tableName”

where “columnName” = ‘specific’

22
Q

How do you accidentally delete all rows from a table?

A

omitting the where clause

23
Q

What is a foreign key?

A

when a column in a table specifically refers to values in a different table with the same column name

24
Q

How do you join two SQL tables?

A

select “tableName”.”columnName”
“otherTableName”.”columnName”
from “tableName”
join “otherTableName” using (“columnNameInCommon”);

25
Q

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

A

select “tableName”.”columnName” as “newName”

26
Q

What are some examples of aggregate functions?

A

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

27
Q

What is the purpose of a group by clause?

A

separate rows into groups and perform aggregate functions on those groups of rows