Jumat, 05 Agustus 2016
DATA TYPE IN MYSQL
In this post BeCoding.tk will discuss the types of data in mysql, mysql data types are divided generally divided into three, that is:
1.Numeric data type
This data type is typically used to store data that is intended for the calculation of figures.The following numeric data types that you can use:
INT
Used to store data in the form of positive and negative integers with a range between -2147483648 to 2147483647. This type of data has a size of 4 bytes (32 bits).
TINYINT
Used to store data in the form of positive and negative integers with a range between -128 to 127. This data type has a size of 1 byte (8 bits)
SMALLINT
Used to store data in the form of positive and negative integers with a range between -32768 to 32,767. This type of data has a size of 2 bytes (16 bits)
MEDIUMINT
Used to store data in the form of positive and negative integers with a range of -8,388,608 to 8,388,607. This type of data has a size of 3 bytes (24 bits)
BIGINT
Used to store data in the form of positive and negative integers with a range of -8,388,608 to 8,388,607. This type of data has a size of 8 bytes (64 bits)
FLOAT
Used to store data in the form of positive and negative fractions single precision. This type of data has a size of 4 bytes (32 bits).
Double
Used to store data in the form of positive and negative fractions double precision. This type of data has a size of 8 bytes (64 bits).
DECIMAL
Used to store data in the form of positive and negative fractions double precision. This type of data has a size of 8 bytes (64 bits).
REAL
Used to store data in the form of positive and negative fractions. This type of data has a size of 8 bytes (64 bits).
NUMERIC
Used to store data in the form of positive and negative fractions. This type of data has a size of 8 bytes (64 bits).
2.String data type
These data types are used to store data in the form of text types.
The following string data types that you can use:
CHAR
Used to store data character / string with a fixed size. This data type has a range between 0 to 255 characters.
VARCHAR
Used to store data character / string with dynamic size. This data type has a range between 0 to 255.
BLOB
BLOB (Binary Large Object) is a data type that is used to store binary data such as files, images, sound, etc. This data type has a range of 216-1 bytes.
TINYBLOB
Used to store binary data such as files, images, and sounds. This data type has a range of 255 bytes.
MEDIUMBLOB
Used to store binary data such as files, images, and sounds. This data type has a range of 244-1 bytes.
LONGBLOB
Used to store binary data such as files, images, and sounds. This data type has a range of 232-1 bytes.
TEXT
Used to store data text. This data type has a range between 0 to 65535 (216-1) characters.
TINYTEXT
Used to store data text. This data type has a range between 0 to 255.
MEDIUMTEXT
Used to store data text. This data type has a range between 0 to 224-1 character.
LONGTEXT
Used to store data text. This data type has a range between 0 to 232-1 character.
ENUM
Enumeration is used to store data (data set)
SET
Used to store the data set of data.
3.Date&Time data type
These types are used to store the data type of the time both date and hour.The following data types Date and Time that you can use:
DATE
Used to store data in a date format yyyy-mm-dd
DATETIME
Used to store date and time data in the format YY: MM: DD HH: MM: SS
TIME
Used to store time data in the format HH: MM: SS
YEAR
Used to store data years.
Now we already know the type of data in MySQL, next we will learn how to write.when we create a table in MySQL, we have to think about the structure first.Now suppose we want to make table 'Purchase' intended to store daily sales data.then the following structure we want, with the result of his input:
Sales_code: contains the sales code (code ranging from NOTA001 - NOTA002).
Item_code: contains the item codes (codes ranging from ITM01 - ITM99).
QTY: contains the amount purchased (1-1000).
Dates: contains the date of purchase (yyyy-mm-dd).
of the above structures we just specify the type of data you want to use, as follows:
Sales_code: using a string data type that is 'char' with a length of 7 digits.
Item_code: using a string data type that is 'char' with a length of 5 digits.
QTY: use the numeric data type is 'int' will be used for the calculation due to the length of 4 digits.
Dates: using date and time data types, namely 'date' with a length of 7 digits.
* Note: for string and numeric data types can be given input constraints or digit.
from the making of the new structure we make the coding to create the table, that is:create table purchase (Sales_code char (7) primary key, Item_code char (5), QTY int (4), dates date);So our explanation of the BeCoding.tk regarding MySQL data types and their way of writing.we hope this post can help you in identifying the type of data in MySQL. We thank you for reading to the end and see you in the next post.
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar