postgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

A relational database management system that uses SQL query language.

mySQL, Microsoft SQL Server, mariaDB, SQLite, Oracle….etc

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
  1. Many problem domains can be modeled well using a relational database; flexibility, you can change the system design after database initially created
  2. relational databases support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible
  3. Sql databases are 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

The ‘top’ command in the terminal to show all the processes currently running

The 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; acts as a description or blueprint of 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 each having the same set of attributes; Tables are used to hold information about the objects to be represented in the database.

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

What is a row?

A

An individual record with a unique id

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

What are some examples of aggregate functions?

A

avg(), sum(), max()/min(), count()…many others

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

What is the purpose of a group by clause?

A

Aggregate functions need a group by clause so it knows with rows to aggregate

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

What is a foreign key?

A

The id for a record from another table;

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

How do you join two SQL tables?

A

SELECT ,

FROM
JOIN USING

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

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

A

Alias the columns or table using AS keyword

. AS

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

How do you delete rows from a database table?

A

DELETE FROM
WHERE = ;
RETURNING *;

RETURNING statement is optional

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

How do you accidentally delete all rows from a table?

A

Use a delete statement without a WHERE clause

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

How do you update rows in a database table?

A
UPDATE  
	SET  = ,
	SET  = ,
	. . .  
   WHERE  ;
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

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

A

INSERT INTO (columnsTuple)
VALUES (valueTuple1),
VALUES (valueTuple2);

or

SET column1 = val1,
column2 = val2;

17
Q

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

A

RETURNING *;

at end of SELECT statement

18
Q

What is SQL and how is it different from languages like JavaScript?

A

It’s declarative instead of imperative - you describe what you want instead of giving instructions for doing something

19
Q

How do you retrieve specific columns from a database table?

A

SELECT ,
,

FROM ;
20
Q

How do you filter rows based on some specific criteria?

A

SELECT . . .
FROM . . .
WHERE ;

21
Q

What are the benefits of formatting your SQL?

A

It’s easier to read

22
Q

What are four comparison operators that can be used in a where clause?

A

= != < > (equal, not equal, less than, greater than)

23
Q

How do you limit the number of rows returned in a result set?

A

SELECT …
FROM …
WHERE …
LIMIT ;

24
Q

How do you retrieve all columns from a database table?

A

SELECT *

FROM ;

25
Q

How do you control the sort order of a result set?

A

SELECT …
FROM …
ORDER BY
LIMIT ;