PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A
  • Relational database management system

- MySQL, Oracle, SQL Server by Microsoft

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 adapted database, so can be a highly transferrable language

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

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
  • Define a schema, and the database will make sure the data conforms to that schema
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
  • Records that are contained inside the table

- All the data that describes one item inside 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

SQL is a declarative language, so we declare or query for data, and the SQL language finds a path to get us the results

JavaScript is imperative, we write functions by hand, so we tell JS how do handle the action as well.

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

If multiple columns, add comma then next column name.

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 keyword with comparison operator between “column” and data (string, number, boolean)

where “column” = data

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

Data is easier to read and comprehend when organized

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 awhereclause?

A

Comparison operators: =, !=, >,

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
  • Using the limit keyword with a number

- 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
  • Ascending order is default

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

Using insert into keyword followed by the “table”, and the column names in double quotes and parenthesis, separated by commas.

insert into actors (firstName, lastName)
values (‘Ken’ ,’Kieu’)

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 in SQL

17
Q

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

A
  • values keyword once
  • Each value should be a new line in parenthesis and single quote

insert into programming (languages)
values (‘HTML’),
(‘CSS’),
(‘JavaScript’);

18
Q

How do you get back the row being inserted into a table without a separateselectstatement?

A

returning *;

or returning specific “column”

19
Q

How do you update rows in a database table?

A
  • update keyword “table”
  • set keyword “column” = value
  • where keyword “column” = value

update store
set price = 100
where item = ‘electronics’;

20
Q

Why is it important to include awhereclause in yourupdatestatements?

A

If where is omitted, it will update all instances of that category

21
Q

How do you delete rows from a database table?

A
  • delete from table
  • where column = value

delete from store
where item = ‘electronics’

22
Q

How do you accidentally delete all rows from a table?

A

If where is omitted, it will delete everything

23
Q

What is a foreign key?

A

Shared attribute that links two tables together

24
Q

How do you join two SQL tables?

A

SELECTorders.orderID, customers.customerName
FROMOrders
JOINcustomersONorders.customerID=customers.customerID;

25
Q

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

A

Using the as keyword will allow you to temporarily rename columns or tables

“actors” as “a”

26
Q

What are some examples of aggregate functions?

A
  • max()
  • min()
  • avg()
  • sum()
  • count()
  • every()
27
Q

What is the purpose of agroup byclause?

A

Group rows that you want to perform aggregate functions on