Ch16: The SQL Sequel Flashcards

1
Q

Describe a one-to-many relationship

A

Each entry in a table relates to many rows

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

Define primary key

A

unique numerical identifier given to an entry

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

Define foreign key

A

Integers that tie directly to primary key of entries in a different table

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

What does the following achieve in MySQL? column_name INTEGER PRIMARY KEY AUTO_INCREMENT

A

Creates a primary key column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
What does the following achieve in MySQL? 
column_name INTEGER,
FOREIGN KEY (column_name) REFERENCES other_table(primary_key_column)
A

Creates a foreign key

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

(T/F) Primary key and foreign key columns should share a name

A

True, this convention helps keep relationships between table clear

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

(T/F) Each table in a database should have a primary key

A

True

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

(T/F) You should define the foreign key column for a table fulfilling the one role of a one-to-many relationship

A

False, add the foreign key column to a table fulfilling the MANY role

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

What performance considerations are there when utilizing a one-to-one relationship

A

Might increase performance overhead to have to link table rows to query related data. However, if some columns are rarely retrieved may make sense to separate them out so only the most frequently used data is queried.

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

(T/F) An additional table is needed to reflect many-to-many relationships

A

True, including a joining/bridging/mapping table that sits between two tables with this relationship is considered a more robust data structure

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

(T/F) When importing tables it is helpful to use the same column names as the external source

A

True

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

Define subquery

A

SQL query embedded in another query. Usually placed within parentheses.

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

(T/F) Subquery must be placed on the left hand side of a comparison operator in a WHERE clause

A

False, place subquery on right hand side of comparison operator in WHERE clause

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

The ____ keyword allows the combining of the results of separate SELECT commands

A

UNION

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

MySQL has no FULL OUTER JOIN syntax. How could you combine all data from two tables in MySQL?

A

Use UNION between LEFT JOIN and RIGHT JOIN queries

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

What does the SQL function MAX(column_name) achieve?

A

Returns largest value in the specified column