Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL database data type

Im new to Database programming and I have a very basic question:

In my PHPMyAdmin GUI that Im using to create tables in my database, what does it mean when the column "type" (ie. datatype) has the data type and something in brackets after that. For example: int(20), bigint(30) .....

I understand the type int and bigint imply the number of bytes that are used and consequently the range of values that can be stored. But what does the value in the brackets mean?

What does the (20) and the (30) stand for.... what impact does this have on....

Sorry if the Q is basic, I am trying to understand databases....

Thanks a lot

like image 961
banditKing Avatar asked Jul 30 '11 20:07

banditKing


1 Answers

Basically this is a Display Width.

I've found very good explanation of this concept here is so decided to not describe it myself and let you read it yourself from the original source.

In the same way that a max-length can be specified for string data types (e.g. VARCHAR(5) = Maximum 5 Characters), Numeric data type cells can have a "Display Length" specified ( E.g.: INT(5) ).

There is a common misconception that specifying a Display Length on an INT column will limit that column's range. As example, it is quite often thought that defining a column as INT(1) will reduce the column's unsigned range to 0 - 9, and that INT(2) would reduce the column's unsigned range to 0 - 99. This is not the case. An INT data column will ALWAYS have a viable unsigned range of 0 - 4294967295, or a signed range of -2147483648 to 2147483647, irrespective of the specified Display Width, whether it be 1 ( INT(1) ) or 20 ( INT(20) ).

  1. Display width doesn't change storage requirements for a data type.
  2. Display width doesn't alter the actual data in any way (ie: it stores the entire value for the data)
  3. A column returns it's full value when called in a query, regardless of the display width (the book directly contradicts this claim it makes as seen above)
like image 138
sll Avatar answered Oct 27 '22 00:10

sll