{"id":445,"date":"2012-07-19T05:46:36","date_gmt":"2012-07-19T05:46:36","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=445"},"modified":"2022-10-20T13:11:25","modified_gmt":"2022-10-20T12:11:25","slug":"column-data-types","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/tables\/column-data-types","title":{"rendered":"Columns Data Types"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Quick Data Types List<\/h4>\n\n\n\n<p>(For a more in depth description see below)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>TINYINT\n\tRange: -128 to 127\n\tC Variable: signed char (int8_t)\n\nTINYINT unsigned\n\tRange: 0 to 255\n\tC Variable: char (uint8_t)\n\nSMALLINT\n\tRange: -32768 to 32767\n\tC Variable: short int (int16_t)\n \nSMALLINT unsigned\n\tRange: 0 to 65535\n\tC Variable: unsigned short int (uint16_t)\n\nMEDIUMINT\n\tRange: -8388608 to 8388607\n\tC Variable: short long (int24_t)\n\nMEDIUMINT unsigned\n\tRange: 0 to 16777215\n\tC Variable: unsigned short long (uint24_t)\n\nINT\n\tRange: -2147483648 to 2147483647\n\tC Variable: int (int32_t)\n \nINT unsigned\n\tRange: 0 to 4294967295\n\tC Variable: unsigned int (uint32_t)\n\nBIGINT\n\tRange: -9223372036854775808 to 9223372036854775807\n\tC Variable: long long int (int64_t)\n\nBIGINT unsigned\n\tRange: 0 to 18446744073709551615\n\tC Variable: unsigned long long int (uint64_t)\n\nFLOAT\n\tRange: \n\tC Variable: float\n\nDOUBLE\n\tRange: \n\tC Variable: double\n\nTIME\n\tRange: \n\tC Variable: MYSQL_TIME\n\nDATE\n\tRange: \n\tC Variable: MYSQL_TIME\n\nDATETIME\n\tRange: \n\tC Variable: MYSQL_TIME\n\nTIMESTAMP\n\tRange: \n\tC Variable: MYSQL_TIME\n\nTEXT\n\tRange: A field with a maximum length of 65535 characters.\n\tC Variable: char&#91;]\n\nCHAR\n\tRange: A fixed-length string between 1 and 255\n\tC Variable: char&#91;]\n\nVARCHAR\n\tRange: A variable-length string up to 65535 characters in length\n\tC Variable: char&#91;]\n\tLength is actually the max length specification.  Whilst you can simply specify a very\n\tlarge value of varchar(max) bear in mind the following:\n\t\t- Temporary tables and MEMORY tables store a VARCHAR column as a fixed-length column,\n\t\tpadded out to its maximum length, so there's a possible performance impact.\n\t\t- The effective maximum length of a VARCHAR is subject to the maximum row \n\t\tsize (65,535 bytes, which is shared among all columns) and the character set used.\n\t\t- If using a multi-byte character (e.g. a utf-8 collation) you will not be able to\n\t\tcreate a varchar with about more than 21000 chars (65535 \/ 3). If you use ascii, you will.\n\t\t- varchar(max) can impact performance so avoid if you can.\n\n \nBLOB\n\tRange: A field with a maximum length of 65535 characters.\n\tC Variable: char&#91;]\n \nBINARY\n\tRange: A fixed-length byte array between 1 and 255\n\tC Variable: char&#91;]\n \nVARBINARY\n\tRange: A variable-length byte array between 1 and 255 characters in length\n\tC Variable: char&#91;]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Numeric<\/h4>\n\n\n\n<p>BOOL<\/p>\n\n\n\n<p>Use&nbsp;TINYINT<\/p>\n\n\n\n<p>BIT<\/p>\n\n\n\n<p>The BIT data type is used to store bit-field values. A type of BIT(M) enables storage of M-bit values. M can range from 1 to 64. &nbsp;(Not universally supported)<\/p>\n\n\n\n<p>INT<\/p>\n\n\n\n<p>A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits (this is just a display width with the left being padded with spaces)<\/p>\n\n\n\n<p>TINYINT<\/p>\n\n\n\n<p>A very small integer that can be signed or unsigned. If signed, the allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits.<\/p>\n\n\n\n<p>SMALLINT<\/p>\n\n\n\n<p>A small integer that can be signed or unsigned. If signed, the allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a width of up to 5 digits.<\/p>\n\n\n\n<p>MEDIUMINT<\/p>\n\n\n\n<p>A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from -8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215. You can specify a width of up to 9 digits.<\/p>\n\n\n\n<p>BIGINT<\/p>\n\n\n\n<p>A large integer that can be signed or unsigned. If signed, the allowable range is from -9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is from 0 to 18446744073709551615. You can specify a width of up to 11 digits.<\/p>\n\n\n\n<p>FLOAT(M,D)<\/p>\n\n\n\n<p>A floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a FLOAT.<\/p>\n\n\n\n<p>DOUBLE(M,D)<\/p>\n\n\n\n<p>A double precision floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE.<\/p>\n\n\n\n<p>DECIMAL(M,D)<\/p>\n\n\n\n<p>An unpacked floating-point number that cannot be unsigned. In unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">INT fields Length value<\/h5>\n\n\n\n<p>The length parameter has no effect on how data is stored.  It just specifies how many characters to pad when selecting data that is also defined as ZEROFILL. So it&#8217;s not important in how the db is used, the length does absolutely nothing unless you use ZEROFILL, where it will determine how many leading zeros are added before a value that is smaller than the length parameter.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Date and Time<\/h4>\n\n\n\n<p>DATE<\/p>\n\n\n\n<p>A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30.<\/p>\n\n\n\n<p>DATETIME<\/p>\n\n\n\n<p>A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.<\/p>\n\n\n\n<p><span style=\"color: #ff0000;\"><em>When adding a DateTime to a table make sure your software hasn&#8217;t set &#8220;On Update Current_Timestamp&#8221; by default otherwise every time there is a an update to the row it will get changed automatically!<\/em><\/span><\/p>\n\n\n\n<p>TIMESTAMP<\/p>\n\n\n\n<p>A timestamp between midnight, January 1, 1970 and sometime in 2037. This looks like the previous DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000 ( YYYYMMDDHHMMSS ).<\/p>\n\n\n\n<p>TIME<\/p>\n\n\n\n<p>Stores the time in HH:MM:SS format.<\/p>\n\n\n\n<p>YEAR(M)<\/p>\n\n\n\n<p>Stores a year in 2-digit or 4-digit format. If the length is specified as 2 (for example YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is specified as 4, YEAR can be 1901 to 2155. The default length is 4.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">String<\/h4>\n\n\n\n<p>CHAR(M)<\/p>\n\n\n\n<p>A fixed-length string between 1 and 255 characters in length (for example CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.<\/p>\n\n\n\n<p>VARCHAR(M)<\/p>\n\n\n\n<p>A variable-length string between 1 and 65535 characters in length; for example VARCHAR(25). You must define a length when creating a VARCHAR field.  VARCHAR has the advantage over text in that it is stored in the row and can be handled in memory by MySQL, disk based access is not required for queries.<\/p>\n\n\n\n<p>BLOB or TEXT<\/p>\n\n\n\n<p>A field with a maximum length of 65535 characters. BLOBs are &#8220;Binary Large Objects&#8221; and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.<\/p>\n\n\n\n<p>TINYBLOB or TINYTEXT<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.<\/p>\n\n\n\n<p>MEDIUMBLOB or MEDIUMTEXT<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.<\/p>\n\n\n\n<p>LONGBLOB or LONGTEXT<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.<\/p>\n\n\n\n<p>JSON<\/p>\n\n\n\n<p>MySQL has a JSON column type. MariaDB considers it a LONGTEXT instead.<\/p>\n\n\n\n<p>ENUM<\/p>\n\n\n\n<p>An enumeration, which is a fancy term for list. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain &#8220;A&#8221; or &#8220;B&#8221; or &#8220;C&#8221;, you would define your ENUM as ENUM (&#8216;A&#8217;, &#8216;B&#8217;, &#8216;C&#8217;) and only those values (or NULL) could ever populate that field.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Files<\/h4>\n\n\n\n<p>BLOB<\/p>\n\n\n\n<p>A field with a maximum length of 65535 characters. BLOBs are &#8220;Binary Large Objects&#8221; and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.<\/p>\n\n\n\n<p>TINYBLOB<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.<\/p>\n\n\n\n<p>MEDIUMBLOB<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.<\/p>\n\n\n\n<p>LONGBLOB<\/p>\n\n\n\n<p>A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Data Types List (For a more in depth description see below) Numeric BOOL Use&nbsp;TINYINT BIT The BIT data type is used to store bit-field values. A type of BIT(M) enables storage of M-bit values. M can range from 1 to 64. &nbsp;(Not universally supported) INT A normal-sized integer that can be signed or unsigned. [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[232,63],"tags":[],"class_list":["post-445","post","type-post","status-publish","format-standard","hentry","category-columns-mysql","category-tables"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":16,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":4423,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/445\/revisions\/4423"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}