June 2010
Intermediate to advanced
328 pages
7h 51m
English
As we saw in Chapter 2, Jaywalking, the best solution is to create a dependent table with one column for the multivalue attribute. Store the multiple values in multiple rows instead of multiple columns. Also, define a foreign key in the dependent table to associate the values to its parent row in the Bugs table.
| Multi-Column/soln/create-table.sql | |
| | CREATE TABLE Tags ( |
| | bug_id BIGINT UNSIGNED NOT NULL |
| | tag VARCHAR(20), |
| | PRIMARY KEY (bug_id, tag), |
| | FOREIGN KEY (bug_id) REFERENCES Bugs(bug_id) |
| | ); |
| | |
| | INSERT INTO Tags (bug_id, tag) |
| | VALUES (1234, 'crash'), (3456, 'printing'), (3456, 'performance'); |
When all the tags associated with a bug are in a single column, searching for bugs ...
Read now
Unlock full access