SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

open source relational database management system

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

widely used.

data is also unlikely to be corrupted

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

top

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 is called a schema. the rules for how a data is sorted

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

What is a table?

A

Relational databases store data in relations, commonly referred to as tables. 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

A table is a list of rows each having the same set of attributes
each row has a list of attributes
each row has the same list of attributes but they probably will have different values

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

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 (for columns) is referred to as a tuple.

example: 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
9
Q

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

A

example:
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 *

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 clause

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

because without that, it will update every row

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 clause

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

using delete without 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

a column that is also represented in another table. these columns match each other and can be used to join other tables together

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

join and using clause

17
Q

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

A
as clause
select "products"."name" as "product",
       "suppliers"."name" as "supplier"
  from "products"
  join "suppliers" using ("supplierId");
18
Q

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

A

SQL is declarative

Javascript is imperative

19
Q

How do you retrieve specific columns from a database table?

A

select “thing”

20
Q

How do you filter rows based on some specific criteria?

A

where clause just has to evaluated true or false

21
Q

What are the benefits of formatting your SQL?

A

easier to read

22
Q

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

A

=, , !

23
Q

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

A

limit clause

24
Q

How do you retrieve all columns from a database table?

A

*

25
Q

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

A

order by

26
Q

What are some examples of aggregate functions?

A
sum()
average()
count()
max()
min()
27
Q

What is the purpose of a group by clause?

A

arrange