Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What column data type should I use for storing large amounts of text or html

I have a column in a table which used to be varchar(255) in the beginning and due to some design changes now it is varchar(1536) = 1024 + 512. I will not be searching or indexing this field, does it make sense to store this value in a different data type other than a varchar if you would like to optimize this for performance?

like image 401
user339108 Avatar asked Mar 28 '11 11:03

user339108


People also ask

Which datatype is ideal for large amount of text?

Answers. Yes varchar(max) is fine. If you want to store large amounts of text in a SQL database, then you want to use either a varchar(max) or a nvarchar(max) column to store that data. In case you don't know the difference, nvarchar will support Unicode characters.

Which data type will you use for storing text data?

To store text we use a STRING data type. Think of a word or sentence as just a list (string) of characters.

Which datatype is used to store long size text in a field?

Long Text In Access web apps, the Long Text field can store up to 2^30-1 bytes, and is equivalent to the SQL Server data type of nvarchar(max).

What can store large string in text type?

The MEDIUMTEXT data object is useful for storing larger text strings like white papers, books, and code backup. These data objects can be as large as 16 MB (expressed as 2^24 -1) or 16,777,215 characters and require 3 bytes of overhead storage.


2 Answers

You should use TEXT like the others said, but there is some important advice every time you use TEXT or BLOB: decouple them form your base table as they really slow down accessing the table. Imagine the following structure:

CREATE TABLE article (     id INT(10) UNSIGNED,     title VARCHAR(40),     author_id INT(10) UNSIGNED,     created DATETIME,     modified DATETIME );  CREATE TABLE article_body (     id INT(10) UNSIGNED,     body TEXT ); 

Whenever you list articles you can use the article table (last 5 articles of author 33):

SELECT id, title FROM article WHERE author_id=33 ORDER BY created DESC LIMIT 5 

And when someone really opens the article you can use something like:

SELECT a.title, ab.body FROM article AS a    LEFT JOIN article_body AS ab ON ab.id = a.id WHERE a.id=82 
like image 114
vbence Avatar answered Sep 23 '22 21:09

vbence


Yes, it will be better if you can store the values in the "TEXT" data type. For more details, please read this article.

Regarding knowledge of storage requirements, you can read this one.

Hope it helps.

like image 21
Knowledge Craving Avatar answered Sep 21 '22 21:09

Knowledge Craving