R
R
Roman Rakzin2017-02-20 23:12:30
SQL
Roman Rakzin, 2017-02-20 23:12:30

Does it make sense to store a byte in a varchar(max) field in this case?

I have a table with fields

  • ParameterId
  • Value[varchar(max)]

The Value field can store a variety of information, from 1 or 0, to large text.
How is memory reserved in a varchar(max) field?
Do they make such a structure as above?
(on the one hand, it makes no sense to allocate memory if you store 1 or 0 in a cell, on the other hand, you need to store the text of the result, which can be long)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2017-02-21
@Sumor

varchar(max) blob type. In SQLServer, it is stored in a separate location from the main record and is not included in the 8kb per record limit. From memory it takes 2 bytes + the size of the stored value. It is better, by the way, to store in nvarchar, since after all it is already the age of Unicode.
If you have data up to 4000 characters, it's better to store it in nvarchar(4000) - the data is stored along with the key.
As long as you do not have millions of records and there are no strict limits on the size of the database, do not complicate and store in a way that is convenient for programmatic processing.

I
igruschkafox, 2017-02-23
@igruschkafox

How is memory reserved in a varchar(max) field?
- varchar Reserves nothing - takes up as much space as needed to store data
reserves another data type - char
Actually, this is one of the main differences between these data types

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question