MEDIUMTEXT

MEDIUMTEXT is a column type in SQL databases. It is used to store large blocks of text, capable of storing up to 16MB or approximately 16,777,215 characters. Encoding can dictate the maximum nubmer of characters, as one character can occupy more than one byte of storage. MEDIUMTEXT is part of the TEXT data type category in SQL. It is used when TEXT's 64KB of storage is insufficient, but LONGTEXT's 4GB is excessive.

Example

CREATE TABLE example_table (
id INT AUTO_INCREMENT,
text_column MEDIUMTEXT,
PRIMARY KEY (id)
);
INSERT INTO example_table (text_column)
VALUES ('This is a very long text...');

Output

Query OK, 0 rows affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)

Explanation

In the provided example, initially a table ‘example_table’ is created with two columns, ‘id’ and ‘text_column’. The ‘id’ column is set as the primary key which auto increments with every new row addition. The ‘text_column’ is defined as ‘MEDIUMTEXT’, a type that can store up to 16 million characters.

A record is inserted into ‘example_table’ with a lengthy string “This is a very long text…” in the ‘text_column’. The Output reflects the successful execution of these operations.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.