Jump to content
xisto Community
Sign in to follow this  
sonesay

Mysql Datatype Int() Question Not sure what value to use inside int()

Recommended Posts

Can anyone clarify what the value in int() actually does?

CREATE TABLE job_class (jc_id int(1) NOT NULL AUTO_INCREMENT PRIMARY KEY,jc_index int(2) NOT NULL,jc_name varchar(20) NOT NULL,jc_type varchar(20) NOT NULL);

I was under the impression that any integer value used inside a () was the limit that data-type would have.In the PRIMARY KEY column I was able to add integer values 1-18. I'm kinda confused now If I can add 2 digit integers there then what is the point of assigning values inside brackets()For the varchar() any number put in there does limit the character allowed. e.g 'test' inserted into varchar(2) would result in 'te'

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

Check this out:

As an extension to the SQL standard, MySQL also supports the integer types TINYINT, MEDIUMINT, and BIGINT. The following table shows the required storage and range for each of the integer types.
Another extension is supported by MySQL for optionally specifying the display width of integer data types in parentheses following the base keyword for the type (for example, INT(4)). This optional display width is used to display integer values having a width less than the width specified for the column by left-padding them with spaces.

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

When used in conjunction with the optional extension attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004. Note that if you store larger values than the display width in an integer column, you may experience problems when MySQL generates temporary tables for some complicated joins, because in these cases MySQL assumes that the data fits into the original column width.

Source: http://dev.mysql.com/doc/refman/5.7/en/numeric-types.html

Note: SQL INT supports -2147483648 to 2147483647 range.

Notice from rvalkass:

Linking to your source is not enough - you need to put any copied material inside QUOTE tags.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.