Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL table structure [closed]

I am trying to decide whether to create a global view table or 1 for each section. for example, Lets say I have products, categories and pages.

Do I have 3 tables e.g:

CREATE TABLE `tbl_products` (
`p_id` INT NOT NULL ,
`p_views` INT NOT NULL ,
INDEX ( `p_id` ) 
) ENGINE = MYISAM 

CREATE TABLE `tbl_categories` (
`c_id` INT NOT NULL ,
`c_views` INT NOT NULL ,
INDEX ( `c_id` ) 
) ENGINE = MYISAM 

CREATE TABLE `tbl_pages` (
`pg_id` INT NOT NULL ,
`pg_views` INT NOT NULL ,
INDEX ( `pg_id` ) 
) ENGINE = MYISAM 

Or do I have 1 table storing all e.g.

CREATE TABLE `tbl_views` (
`view_id` INT NOT NULL ,
`view_type` VARCHAR( 10 ) NOT NULL ,
`view_views` INT NOT NULL ,
INDEX ( `view_id` ) 
) ENGINE = MYISAM 

Where view_type is either products, categories or pages.

What would the advantages/disadvantages be of each solution?

Thanks in advance.

like image 718
Lizard Avatar asked May 08 '26 19:05

Lizard


1 Answers

I really like the 1 table method, this keeps the database uncluttered, which i think is important.

Also, later on you may want to add another type, you wouldnt have to add another table, just a row with a different view_type.

like image 131
John Boker Avatar answered May 11 '26 08:05

John Boker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!