Does varchar (max) = varchar?

I noticed that I can write

SELECT CAST(Min(mynumber) AS VARCHAR(Max))+'mystring' AS X 

a

 SELECT CAST(Min(mynumber) AS VARCHAR)+'mystring' X 

I'm sorry to refuse the (Max) parameter?

+4
source share
3 answers

If the varchar word is not specified in the declaration definition or variable declaration, the default length is 1. When it is not specified when using the CAST and CONVERT functions, the default length is 30.

See: char and varchar (Transact-SQL)

I feel that poor code usage is not possible by specifying a length for varchar.

+2
source

You will regret this (in the unlikely) situation that MAX(mynumber) has more than 30 characters:

When n is not specified when using the CAST and CONVERT , the default length is 30.

+8
source

VARCHAR (MAX) should be used for Large Objects.It uses regular data until the content actually fills 8k of data. When an overflow occurs, the data is saved as the old TEXT, IMAGE, and the pointer replaces the old content. Varchar is for variable-length character data, not Unicode. n can be a value from 1 to 8000. Max indicates that the maximum storage size is 2 ^ 31-1 bytes. Hope this helps.

+3
source

Source: https://habr.com/ru/post/1314083/


All Articles