-1

I cant understand the difference between int(1) and int(8), because int(1) can have 999.9999 too.

If so, where is the difference? Does the length modifier on the INT datatype influence the range of values that can be stored? For example, can a six digit number be stored in an INT(1) column?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
özgür
  • 43
  • 5
  • The datatype is INT. The length modifier (the `(1)` in your example) has no impact on the values that can be stored. That length modifier is available to a client application, which can interpret that as a specification for the number of characters that should be used for display of the value. The INT datatype allows for up to 10 decimal digits, so a maximum of 11 characters is needed to display it (10 digits plus 1 character for the negative sign.) – spencer7593 Aug 16 '12 at 16:15
  • @spencer7593 - Editing the question to insert your answer is not a valid edit. I've tried to incorporate your improved question wording within the question, though. Take a look at this, and if you still feel it should be reopened, flag us about it. – Brad Larson Aug 16 '12 at 17:36
  • @Brad Larson - I agree that the original question was a bit vague, but it was NOT at all difficult to figure out what the OP was asking -- he was asking about the the effect of the length modifier on the INT datatype. While I was composing an answer, before I could post it, the question was closed as "not a real question". This is a real question, and I am just trying to assist this particular user. – spencer7593 Aug 16 '12 at 18:51

1 Answers1

2

That is an optional definition. It does not define the size of the int field. It defines the representation. If you add ZEROFILL to the definition the rest of the field will be filled with zeros otherwise with spaces.

See NUMERIC TYPES

The benefits are explained here

Community
  • 1
  • 1
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • ı want to ask that example: personel_number unsigned tinyint(8) and then a write a record there : 999 999 personel_numer is 256. now int example personal_number unsigned int(2) and write a record 999 999 personel number is 999 999 so the same astiny int int(x), what is the effect of "x" ? – özgür Aug 16 '12 at 16:23
  • it s a shock for me. everwhere,all documentaiton,lesson teach int(3), int(7),int(8) ... but the number has no effect. ı m in crisses.just angry bird.oo no! o Allah!... so the result:number has no effect for int,mediumint,smallint, but effect tinyinnt,char,varchar ? true ? – özgür Aug 16 '12 at 17:02
  • 2
    for `char` and `varchar` the `()` defines the length of the string. for `int`types it is just the representation how the rest of the number will be displayed. for `numeric` types it defines the precision. You should study [data types](http://dev.mysql.com/doc/refman/5.0/en/data-types.html) – juergen d Aug 16 '12 at 18:40
  • 1
    @user1603766: it's true that the length modifier on integer datatypes has NO EFFECT on the datatype within the database, but it IS available to client applications, where the client application can base its behavior based on the value specified. For example, the mysql command line client uses this value when presenting a formatted result set. – spencer7593 Aug 16 '12 at 18:57