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?
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.
To store text we use a STRING data type. Think of a word or sentence as just a list (string) of characters.
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).
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With