The ____ Data Type Can Store Up to a Gigabyte of Text.
Summary: in this tutorial, you volition learn how to apply MySQL TEXT for storing text data in the database table.
Introduction to MySQL TEXT data type
Besides CHAR and VARCHAR character types, MySQL provides usa with TEXT type that has more features which CHAR and VARCHAR cannot embrace.
The TEXT is useful for storing long-class text strings that can take from 1 byte to 4 GB. We oftentimes find the TEXT data type for storing article torso in news sites, product description in due east-commerce sites.
Different from CHAR and VARCHAR, yous don't have to specify a storage length when y'all use a TEXT type for a column. Also, MySQL does non remove or pad spaces when call up or insert text information like CHAR and VARCHAR.
Note that the TEXT information is not stored in the database server's memory, therefore, whenever y'all query TEXT data, MySQL has to read from it from the deejay, which is much slower in comparing with CHAR and VARCHAR.
MySQL provides four TEXT types: TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT.
The post-obit shows the size of each TEXT type with the supposition that we are using a character set that takes ane byte to shop a graphic symbol
TINYTEXT – 255 Bytes (255 characters)
The maximum characters that TINYTEXT tin shop is 255 ( 2^8 = 256, 1 byte overhead).
Yous should use TINYTEXT for the cavalcade that requires less than 255 characters, has inconsistent length, and does not crave sorting such every bit the excerpt of a blog post and summary of an article.
See the following example:
CREATE Table articles ( id INT AUTO_INCREMENT Chief Central, title VARCHAR(255), summary TINYTEXT );
Lawmaking language: SQL (Structured Query Language) ( sql ) In this example, we created a new table named articles that has a summary cavalcade with the data type is TINYTEXT.
TEXT – 64KB (65,535 characters)
The TEXT information blazon can hold up to 64 KB that is equivalent to 65535 (2^16 – one) characters. TEXT besides requires 2 bytes overhead.
The TEXT can hold the torso of an article. Consider the post-obit example:
ALTER Tabular array articles ADD Cavalcade trunk TEXT Not Null Afterward summary;
Code language: SQL (Structured Query Language) ( sql ) In this case, we added the body column with TEXT datatype to the articles table using the Modify Tabular array statement.
MEDIUMTEXT – 16MB (16,777,215 characters)
The MEDIUMTEXT can agree up to 16MB text data that is equivalent to xvi,777,215 characters. It requires iii bytes overhead.
The MEDIUMTEXT is useful for storing quite large text data similar the text of a volume, white papers, etc. For example:
CREATE TABLE whitepapers ( id INT AUTO_INCREMENT PRIMARY KEY, body MEDIUMTEXT Not Aught, published_on DATE Non Zippo );
Code language: SQL (Structured Query Language) ( sql ) LONGTEXT – 4GB (4,294,967,295 characters)
The LONGTEXT can store text information up to four GB, which is a lot. It requires 4 bytes overhead.
In this tutorial, you have learned how to use various MySQL TEXT data types for storing text in database tables.
Was this tutorial helpful?
johnsonwituarmay38.blogspot.com
Source: https://www.mysqltutorial.org/mysql-text/
0 Response to "The ____ Data Type Can Store Up to a Gigabyte of Text."
Post a Comment