Ch16: The SQL Sequel Flashcards
Describe a one-to-many relationship
Each entry in a table relates to many rows
Define primary key
unique numerical identifier given to an entry
Define foreign key
Integers that tie directly to primary key of entries in a different table
What does the following achieve in MySQL? column_name INTEGER PRIMARY KEY AUTO_INCREMENT
Creates a primary key column
What does the following achieve in MySQL? column_name INTEGER, FOREIGN KEY (column_name) REFERENCES other_table(primary_key_column)
Creates a foreign key
(T/F) Primary key and foreign key columns should share a name
True, this convention helps keep relationships between table clear
(T/F) Each table in a database should have a primary key
True
(T/F) You should define the foreign key column for a table fulfilling the one role of a one-to-many relationship
False, add the foreign key column to a table fulfilling the MANY role
What performance considerations are there when utilizing a one-to-one relationship
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.
(T/F) An additional table is needed to reflect many-to-many relationships
True, including a joining/bridging/mapping table that sits between two tables with this relationship is considered a more robust data structure
(T/F) When importing tables it is helpful to use the same column names as the external source
True
Define subquery
SQL query embedded in another query. Usually placed within parentheses.
(T/F) Subquery must be placed on the left hand side of a comparison operator in a WHERE clause
False, place subquery on right hand side of comparison operator in WHERE clause
The ____ keyword allows the combining of the results of separate SELECT commands
UNION
MySQL has no FULL OUTER JOIN syntax. How could you combine all data from two tables in MySQL?
Use UNION between LEFT JOIN and RIGHT JOIN queries