SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database management system written using a variation of SQL; other examples of relational databases include MySQL, SQL Server, and Oracle

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

It is used everywhere and is generally better at modeling 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

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 in a database; a formal description of how the data 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 collection of rows in a database that all share the same columns(attributes)

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

What is a row?

A

An instance of data containing columns(attributes)

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 stands for Structured Query Language and is the primary way of interacting with relational databases; it is a declarative language (e.g. HTML and CSS) where the programmer uses pre-built keywords to describe the desired result, as opposed to a imperative language (e.g. JavaScript) where the programmer tells the program what to do and how to do it

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

from “table”

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

where “attribute” = criteria

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

It makes it easier to read

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 a where clause?

A

=, !=, >, ‘less than sign’

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

limit number

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

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

insert into “table” (“attribute1”, “attribute2”, …)

values (“value1”, “value2”, …)

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 enclosed in parentheses

17
Q

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

A

separate the tuples with commas

18
Q

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

A

returning *

19
Q

How do you update rows in a database table?

A

update “table”
set “attribute” = newValue
where “attribute” = criteria

20
Q

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

A

Otherwise, SQL will update every row in the table

21
Q

How do you delete rows from a database table?

A

delete from “table”

where “attribute” = criteria

22
Q

How do you accidentally delete all rows from a table?

A

You exclude the where clause

23
Q

What is a foreign key?

A

A column in a table that is used in another table, which allows the tables to be joined

24
Q

How do you join two SQL tables?

A

from “firstTable”

join “secondTable” using (“foreignKey”)

25
Q

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

A

“originalName” as “newName”

26
Q

What are some examples of aggregate functions?

A

count(), sum(), max(), min(), avg()

27
Q

What is the purpose of a group by clause?

A

It specifies the data on which to apply the aggregate functions