Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many fields is normal to have in one table?

Tags:

mysql

Ok, I am creating a game, I have one table where I save a lot of information about a member, so I have many field in it. How many fields is normal to have in one table? Does it matter? Maybe I should split that info into two-three-four tables? What do you think?

like image 844
good_evening Avatar asked Dec 22 '22 01:12

good_evening


2 Answers

Normalize the Database

If you feel you have too many columns, you probably have repeating groups, which suggests you should normalize the database. See an example here: Description of the database normalization basics

Hard MySQL Limits

MySQL 5.5 Column Count Limit

Every table has a maximum row size of 65,535 bytes.

There is a hard limit of 4096 columns per table

like image 182
bakkal Avatar answered Jan 11 '23 11:01

bakkal


Splitting of data into tables should generally not be dictated by the number of columns, but by the nature of the data. The process of splitting a large table into smaller ones is called normalization.

The only other reason I can think of to split a table is, if you may need data in clusters, i.e. you often need columns A-D together or columns E-L, but never all columns or columns D-F, then you can split the table into two tables, one containing columns A-D and the primary key, the other one containing columns E-L and the primary key.

like image 35
Janick Bernet Avatar answered Jan 11 '23 10:01

Janick Bernet