codesnout.com

SQL - MySQL Data Types

Google Ads

SQL - MySQL Data Types


MySQL Data Types

MySQL contains 3 main Data Types;

  1. Text (String / Character Types)
  2. Numeric
  3. Date/Time

Text Types:

The example below specifies a maximum number size of 50 characters for the data type VARCHAR()

Example: VARCHAR(50)

Data Type Use and Description Storage Size
CHAR(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in the (size) parameter. Can store up to 255 characters
VARCHAR(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in (size) the parameters. Can store up to 255 characters. If you put a greater value than 255 it will be converted to a TEXT type
TINYTEXT Holds a string with a maximum length of 255 characters 0-255 Characters
TEXT Holds a string with a maximum length of 65,535 characters 0-65535 Characters
MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters 0-16777125 Characters
LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters 0-4,294,967,295 characters
BLOB For BLOBs (Binary Large OBjects). Holds up to 0-65,535 bytes of data
MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data 0-16,777,215 bytes of data
LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data 0-4,294,967,295 bytes of data
ENUM(x,y,z,etc.) Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.
Note: The values are sorted in the order you enter them.
You enter the possible values in this format: ENUM('X','Y','Z')
Column is exactly 1 of 1-65,535 values
SET Similar to ENUM except that SET may contain up to 64 list items and can store more than one choice Column is 0 or more values in list of 1-64 members

 


MySQL Numeric Types:

The example below specifies a maximum number size of 50 for the data type TINYINT()

Example: TINYINT(50)

Data Type Use and Description Storage Size
TINYINT(size) -128 to 127 normal. 0 to 255 UNSIGNED. The maximum number of digits may be specified in the (size) parameter. 1 Byte
SMALLINT(size) -32768 to 32767 normal. 0 to 65535 UNSIGNED. The maximum number of digits may be specified in the (size) parameter. 2 Bytes
MEDIUMINT(size) -8388608 to 8388607 normal. 0 to 16777215 UNSIGNED. The maximum number of digits may be specified in the (size) parameter. 3 Bytes
INT(size) -2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED. The maximum number of digits may be specified in the (size) parameter. 4 bytes
BIGINT(size) -9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED. The maximum number of digits may be specified in the (size) parameter. 8 Bytes
FLOAT(size,digits) A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the digits parameter 4 or 8 Bytes
DOUBLE(size,digits) A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the digits parameter 8 Bytes
DECIMAL(size,digits) A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the digits parameter  
The integer types have an extra option called UNSIGNED. Normally, the integer ranges from a negative to a positive value. Using UNSIGNED will raise that range up so it begins at zero instead of a negative number.

 


MySQL Date/Time Types:

 

Data Type Use and Description Storage Size
DATE() A date. Format: YYYY-MM-DD The supported range is from '1000-01-01' to '9999-12-31' 3 Bytes
DATETIME() A date and time combination. Format: YYYY-MM-DD HH:MM:SS. The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59' 8 Bytes
TIMESTAMP() A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD HH:MM:SS The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC 4 Bytes
TIME() A time. Format: HH:MM:SS The supported range is from '-838:59:59' to '838:59:59' 3 Bytes
YEAR() A year in two-digit or four-digit format. Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069 1 Byte

 


Related SQL Sample Code:


About Us | Privacy Policy | Contact Us | ©2010 Thunderousity Information Management Solutions | www.autosnout.com - Car Performance Statistics Website Utilising SQL | SQL Blog |

SQL Home | SQL Intro | SQL SELECT Statement | DISTINCT | WHERE | SQL Wildcards | AND OR | IN | BETWEEN | LIKE | ORDER BY | GROUP BY | TOP | ALIAS | DELETE | INSERT | UPDATE | CREATE DATABASE | CREATE TABLE | ALTER | INNER JOIN | FULL JOIN | LEFT JOIN | RIGHT JOIN | UNION | CONSTRAINTS | NOT NULL| Aggregate Functions | SUM | AVG | COUNT | MAX | MIN | FIRST | LAST | GROUP BY | HAVING | LIMIT | Microsoft Access Data Types | MySQL Data Types | SQL Server Data Types | ASCII HTML Reference Sheet |