sql Flashcards

1
Q
  1. What is SQL and how is it different from languages like JavaScript?
A

a. Structured Query Language (SQL) is the primary way of interacting with relational databases.
b. It is a powerful way of retrieving, creating, and manipulating data in a relational database.
c. Difference: JavaScript is an imperative language while because SQL is a declarative language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. How do you retrieve specific columns from a database table?
A

a. Use the select keyword followed by the “columns” in double quotes, separated by commas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. How do you filter rows based on some specific criteria?
A

a. Use the “where” keyword followed by a condition you are looking to compare or match.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What are the benefits of formatting your SQL?
A

a. Cleaner and easier to read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What are four comparison operators that can be used in a where clause?
A

a. “=” / “ < ” / “ > ” / “ != ”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. How do you limit the number of rows returned in a result set?
A

a. Use the limit keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How do you retrieve all columns from a database table?
A

a. Replace the list of column names with an asterisk ( * )
i. The order of the results is NOT predictable.
ii. The asterisk is NOT in quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How do you control the sort order of a result set?
A

a. Use the order by keywords, followed by desc or asc abbreviated keywords without double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. How do you add a row to a SQL table?
A

a. Use the INSERT statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What is a tuple?
A

a. Tuples are unordered sets of known values with names.
b. Tuple is often referred to as rows in a relational database model.
c. They are effectively a data structure like an array – New Tim.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. How do you add multiple rows to a SQL table at once?
A

a. Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. How do you get back the row being inserted into a table without a separate select statement?
A

a. returning *;

b. sometimes you don’t need to use the return keyword and can specify the columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. How do you update rows in a database table?
A

a. Use the ‘UPDATE’ statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. Why is it important to include a where clause in your update statements?
A

a. If you don’t use a WHERE statement, it will updated EVERY row in the table.
b. Great care must be taken to include a “WHERE” clause in order to ONLY target specific rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. How do you delete rows from a database table?
A

a. Use the “DELETE” statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. How do you accidentally delete all rows from a table?
A

a. By failing to target specific rows and including a where clause – we may accidently delete the entire table.

17
Q
  1. How do you accidentally delete all rows from a table?
A

a. By failing to target specific rows and including a where clause – we may accidently delete the entire table.

18
Q
  1. What is a foreign key?
A

c. A foreign key is a constraint that one column has to match of another column – New Tim.

19
Q
  1. How do you join two SQL tables?
A

a. Use the JOIN statement

20
Q
  1. How do you temporarily rename columns or tables in a SQL statement?
A

a. Use aliases.

21
Q
  1. What are some examples of aggregate functions?
A

a. max()
b. avg()
c. count()

22
Q
  1. What is the purpose of a group by clause?
A

a. Sometimes you don’t want to ask a question about every row in a table. Instead, you want to separate rows into groups and perform aggregate functions on those groups of rows.
b. It groups multiple rows into one bucket row.
c. For each group by, you are actually increasing the row count as there are more things that need to match.