PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS)

Relational Database: database based on relational model of data

Other relational databases: SQLite, NexusDB, Oracle, SQL Azure

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 can store and modify data in a way that makes data corruption as unlikely as possible.

Also good for storing related data

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 -command

check if service is running in top command

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 and basically 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 table is a list of rows each having the same set of attributes

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

What is a row?

A

One entry for attributes

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

How do you add a row to a SQL table?

A

insert into statement

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);

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

What is a tuple?

A

A list of values is referred to as a tuple

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

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

A

values comma separated list of tuples

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;

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

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

A

returning clause

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

How do you update rows in a database table?

A

update statement followed by set statement

update “products”
set “price” = 100;

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

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

A

Without a where clause, everything will be updated

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

How do you delete rows from a database table?

A

Delete statement

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

How do you accidentally delete all rows from a table?

A

Not including a where clause

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

What is a foreign key?

A

Values in a column that links the table to another table

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

How do you join two SQL tables?

A

Use join clause

join + “tableName” + using + (“foreign key name”)

17
Q

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

A

using “as” keyword

i.e.
“s”.”name” as “supplier”,