Introduction to MySQL Data Types
Before creating Tables, you should know about data types. Data types have an elegant role while creating tables. Data types apply to fields. Every column stores a different kind of value in any table.
Data types are used to define what kind of value the store will store. Every column is defined when creating the data type table.
In this tutorial, I’m just telling you about data types. You can learn how to use them in the tables. MySQL data types can be divided into 4 major categories.
- Numeric
- Character String
- Binary String
- Temporal
Numeric Data Types
Numeric data types are used to store numeric values. Numeric types have been divided into 4 categories. These are being given below.
1.Integer
Integer types are used to store whole numbers. Whole numbers are numbers that do not have fractional part (decimal and numbers after that).
2.Floating point
Floating point numbers are numbers that include the fractional part (decimal and the number after that).
3.Fixed Point Types
Fixed point data types are used to store decimal numbers. Decimal numbers contain a number that is integer, in which the fractional part can also be included.
4.Bit type
Bit data type presents the bit field value. In the Bit data type, you enter the width, it shows how many bits of the value to store.
Character String Data Types
Character string data types represent alphanumeric values (number and character). Character string is a very valuable data type, many programming languages use it.
There are 3 types of character string data types in MySQL, let’s try to know them.
1.Char
Char is a fixed length data type. When you define a column of char type, you have to specify the maximum length (the number of bytes you want to store). You can not store a value greater than that length.
2.VarChar
VarChar is a variable length data type. You can also store values of more size than the length you are given in it.
3.Text
Text type stores unstructured text. These can store the value of the text variable length.
Binary String Data Type
Binary values are sequences of bytes. It is stored as a pair of 8 bits. You can also store images, sounds, movies, and executable files in the Binary string data types. Because these are all in binary format. There are 2 types of binary string data types in MySQL.
1.Binary
This data type is the same as char but it stores binary byte strings.
2.VarBinary
This is similar to the data type varchar but it stores the binary byte string.
Temporal Data Type
In MySQL, date and time types are called temporal types. In such data types, you can store temporal information such as time, year, date etc. Temporal data types are of 5 types.