I wonder if any better practice or any principle when come to design a lookup table.
I intend to design an abstract lookup table which can serve many different situations.
For instance, I call my lookup table as a masters and slaves table,
CREATE TABLE IF NOT EXISTS `masters_slaves` (
`mns_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`master_id` varchar(255) DEFAULT NULL COMMENT 'user id or page id',
`slave_id` varchar(255) DEFAULT NULL COMMENT 'member id or user id or page id',
`cat_id` varchar(255) DEFAULT NULL COMMENT 'category id',
`mns_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`mns_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`mns_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
so this lookup table can server the relationship of these types like,
Admins and Members
Admins and Pages
Admins and Posts
Post Categories and Posts
Page Parents and Pages
etc
the cat_id in masters and slaves table will describe and differentiate these categories. for instance, cat_id 1 is Admins and Members and so on.
And I will insert:
- admin id into the column of
master_idand member id into
slave_idcolumn - parent page id into the column of
master_idand child page id into
slave_idcolumn - post categories id into the column
ofmaster_idand page id into
slave_idcolumn - etc
But I am sure about it whether I should go for it or not:
- Is this a good lookup
table practice or should do many create more
than one lookup tables for different
relationships? - If I can do the lookup table like
this, which is only one lookup table
for all, what consequences I will
have in the future? Will this sole
lookup table will be over populated
when my site content grows? - Another thing come to mind is that –
isn’t the tag system a lookup table
solution too?
Thanks.
From my experience it is better to create a lookup table for each category.
Here are the benefits as i see them:
I think there are more pros for having a few smaller tables than one big one.