MYSQL table structure

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

Do I have 3 tables, for example:

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 I have 1 table storing everything, for example.

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 will be the advantages / disadvantages of each solution?

Thanks in advance.

+3
source share
4 answers

I really like the 1 table method, this keeps the database uncluttered, which, in my opinion, is important.

In addition, later you can add another type, you will not need to add another table, just a row with a different view_type.

+2

, , no. 3 , . view_type

0

. - , , . , , - view_type. , (: "", "x", "" - "Y" ), ( ).

0

, , , . , .

+ + , . , (: ), . , () , .

. , , . -, .

Example. If the products require additional information (such as style, price, or who can view it) but the pages and categories are never executed, the table will reserve a space that the pages and categories will never use. Then the Pages and Category entries start to look stupid, mixed with Products.

0
source

Source: https://habr.com/ru/post/1719651/


All Articles