Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we limit length of columns values in MYSQL

Tags:

database

mysql

When we creating database for our application, We limited lengths of database columns.

example -

  1. String (200)
  2. int (5)

etc

Is there any effect on Speed or some effect?

like image 788
Hein Zaw Htet Avatar asked Nov 08 '12 10:11

Hein Zaw Htet


People also ask

Does number of columns affect performance in MySQL?

If you have 42 columns to store and you are selecting only 4 columns, then yes the other columns can affect the query since it increases the amount of disk I/O the server uses to select the wider table.

What is length values in MySQL?

The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

What is the maximum number of columns in a MySQL table?

MySQL has hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact column limit depends on several factors: The maximum row size for a table constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size.


1 Answers

First of all, one does not limit the length of a "database". Instead, one does limit the size of columns of tables in a database.

Why do we do this, you ask?

  1. We don't want to waste any space for data that's never going to use it (that's what the varchar, varbinary and the like are for).
  2. It's a best practice because it forces you to think of your data structure BEFORE you actually use it.
  3. The less data there is the faster the processing of the application (that's a tautology).
  4. It makes it easier to validate your data if you know exactely how much space it is allowed to take.
  5. Full text indexes gain greatly when limited in size
like image 50
aefxx Avatar answered Oct 03 '22 18:10

aefxx