Share this post! | Vote this! |
|
Often times, we sacrifice some usability in our data in order to follow nth-normal form in our database architecture.
The following is a trick that allows us to retrieve name-value pairs of data as denormalized column-value pairs.
Let's take the case of a user settings table. A typical denormalized user settings table may look like this:
CREATE TABLE denormalized_settings (
user_id int NOT NULL,
setting1 varchar(255) NULL,
setting2 varchar(255) NULL,
setting3 varchar(255) NULL,
setting4 varchar(255) NULL
);
INSERT INTO denormalized_settings (user_id, setting1, setting2, setting3, setting4) VALUES
(1, 'hi', '0', '1', '0'),
(2, '0', '1', NULL, '1'),
(3, '1', '0', '1', NULL);
More...
The following is a trick that allows us to retrieve name-value pairs of data as denormalized column-value pairs.
Let's take the case of a user settings table. A typical denormalized user settings table may look like this:
CREATE TABLE denormalized_settings (
user_id int NOT NULL,
setting1 varchar(255) NULL,
setting2 varchar(255) NULL,
setting3 varchar(255) NULL,
setting4 varchar(255) NULL
);
INSERT INTO denormalized_settings (user_id, setting1, setting2, setting3, setting4) VALUES
(1, 'hi', '0', '1', '0'),
(2, '0', '1', NULL, '1'),
(3, '1', '0', '1', NULL);
More...
0 comments:
Post a Comment