SQL / PostgreSQL Flashcards

1
Q

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

A

SQL is a querying language, unlike JavaScript it’s declarative, the user declares the desired end-result and doesn’t actually program how it’s achieved.

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

How do you retrieve specific columns from a database table?

A

select “columnNameOne”, “columnNameTwo” from “table”

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

How do you filter rows based on some specific criteria?

A

where “attribute” = ‘value’

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

What are the benefits of formatting your SQL?

A

Easier readability for others and your future self.

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

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

A

=, !=, greater than, less than

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

How do you retrieve all columns from a database table?

A

select * from “table”

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

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

A

order by “attributeName”

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

How do you add a row to a SQL table?

A

insert into “table” (“attrOne”, “attrTwo”, … “attrN”)

values (‘valOne’, ‘valTwo’, … ‘valN’)

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

What is a tuple?

A

A row of data in a table.

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

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

A

Add more tuples after values and separate them with commas.

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

How do you update rows in a database table?

A

update “table”
set (“colOne” = ‘valOne’, “colTwo” = ‘valTwo’, … “colN” = ‘valN’)
where condition;

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

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

A

So updates are only applied to the desired rows.

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

How do you delete rows from a database table?

A

delete from “table”

where condition;

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

How do you accidentally delete all rows from a table?

A

You forget the where statement.

17
Q

What is a foreign key?

A

A key that refers a primary key on another table.

18
Q

How do you join two SQL tables?

A

select * from “tableOne”

join “tableTwo” using (“sharedKey”)

19
Q

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

A

select “name” as “tempName” from “table” as “tempTable”

20
Q

What are some examples of aggregate functions?

A

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

21
Q

What is the purpose of a group by clause?

A

The group by clause groups rows that share common attributes in separate groups before performing aggregate functions on each of them.

22
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database management system. Other RDBMS include MySQL, SQL Server by Microsoft, and Oracle DB.

23
Q

What are some advantages of learning a relational database?

A

They are widely used in tech.

24
Q

What is one way to see if PostgreSQL is running?

A

Run “sudo service postgresql status” in the command line.

25
Q

What is a database schema?

A

A schema is a collection of tables.

26
Q

What is a table?

A

A list of rows that share the same set of attributes.

27
Q

What is a row?

A

A single structured entry in the table.