postgreSQL, SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

a powerful, free, open source Relational Database Management System (RDBMS). It is often cited as the most advanced open source database of its kind.

alternative relational db: MySQL, SQL Server by Microsoft, and Oracle by Oracle Corporation.

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

Many problem domains can be modeled well using a relational database.
they support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible.
the most widely used kind of database
satisfies ACID properties
doesnt require a complex structure

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’

top command

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

pgweb

A

is just a web interface for interacting w/ postgresql (so its easier)
there are many web interfaces like pgweb, this is not the only one

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

psql

A

what you write in terminal to give commands w/ postgresql

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

What is a database schema?

A

defines how the data in a relational database should be organized.
collection of tables

the structure of the whole database, the “blueprint”

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

What is a table?

A

list of rows each having the same set of attributes.

defines what attribures(column) each row should have

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

What is a row?

A

a single record of data in a table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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.

SQL is a declarative programming language while JS is a imperative programming language

(declarative: programmers describe the results they want and the programming environment comes up with its own plan for getting those results)
(imperative: you basically tell the JavaScript runtime what to do and how to do it)

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

How do you retrieve specific columns from a database table?

A

select “column name”,
“column name”,
etc.
from “name of table”

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

How do you filter rows based on some specific criteria?

A

where “column name” = or > or < or != ‘criteria’

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

What are the benefits of formatting your SQL?

A

cleaner, easier to read, easier to tell what is going on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

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

A

limit clause

give num of rows you want at most

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

How do you retrieve all columns from a database table?

A
  • (an asterisk) instead of column names
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

order by “column name”

*will be ascending order by default
can use order by “column name” desc for it to be in descending order

17
Q

How do you add a row to a SQL table?

A

insert into “table name” (column1 name, column2 name, etc)

values (value for column1, value for column2, etc)

18
Q

What is a tuple?

A

a list of values (in SQL)

a row/a record

19
Q

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

A

list tuples separated by commas

20
Q

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

A

returning keyword *;
or
returning keyword specific column names;
(if you don’t want entire row returned)

21
Q

How do you update rows in a database table?

A
update "table name"
      set "column name" = 'new value',
            "column name" = 'new value',
                                    etc.
 where "column name" = < > != 'value/condition';
22
Q

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

A

if there is no where clause, it will update every row of table

23
Q

How do you delete rows from a database table?

A

delete from “table name”

where “column name” = > < != ‘value/condition’

24
Q

How do you accidentally delete all rows from a table?

A

by not adding a where clause!!

25
Q

What is a foreign key?

A

a column in a table where its values are constrained to match that of a column of another table
can be used to join tables together

constraint that one column has to match the values of another column in another table

26
Q

How do you join two SQL tables?

A

join keyword

select "column1",
            "column2",
                 etc.
   from "table1 name"
     join "table2 name" using ("foreign key")
27
Q

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

A

as keyword

select “columns1”
from “columns” as “all columns”

28
Q

What are some examples of aggregate functions?

A

max(), sum(), count(), min(), average() etc

29
Q

What is the purpose of a group by clause?

A

useful when you want to separate rows into groups and perform aggregate functions on those groups of rows

arrange multiple rows into one row based on a set of conditions or a value of a single row
groups row into a single row based on criteria (one or more columns to group by)
*all rows with same value in the stated columns will collapse into one row

30
Q

what do aggregate functions do?

A

convert a bunch of values into a single value
performs a calculation on a set of values, and returns a single value.

similar to array.reduce()?