SQL Data Types
Data types are used to represent the nature of the data that can be stored in the database table. For example, in a particular column of a table, if we want to store a string type of data then we will have to declare a string data type of this column.
Data types mainly classified into three categories for every database.
- String Data types
- Numeric Data types
- Date and time Data types
Data Types in MySQL, SQL Server, and Oracle Databases
MySQL Data Types
A list of data types used in MySQL database. This is based on MySQL 8.0.
MySQL String Data Types
|CHAR(Size)||It is used to specify a fixed length string that can contain numbers, letters, and special characters. Its size can be 0 to 255 characters. Default is 1.|
|VARCHAR(Size)||It is used to specify a variable length string that can contain numbers, letters, and special characters. Its size can be from 0 to 65535 characters.|
|BINARY(Size)||It is equal to CHAR() but stores binary byte strings. Its size parameter specifies the column length in the bytes. Default is 1.|
|VARBINARY(Size)||It is equal to VARCHAR() but stores binary byte strings. Its size parameter specifies the maximum column length in bytes.|
|TEXT(Size)||It holds a string that can contain a maximum length of 255 characters.|
|TINYTEXT||It holds a string with a maximum length of 255 characters.|
|MEDIUMTEXT||It holds a string with a maximum length of 16,777,215.|
|LONGTEXT||It holds a string with a maximum length of 4,294,967,295 characters.|
|ENUM(val1, val2, val3,...)||It is used when a string object having only one value, chosen from a list of possible values. It contains 65535 values in an ENUM list. If you insert a value that is not in the list, a blank value will be inserted.|
|SET( val1,val2,val3,....)||It is used to specify a string that can have 0 or more values, chosen from a list of possible values. You can list up to 64 values at one time in a SET list.|
|BLOB(size)||It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.|