Best data type for storing rows in SQL Server?

What is the best data type used to store strings, such as a name? I have seen how varchar and nvarchar are used. Which one is better? Does it matter?

I also heard that the best length to use is 255, but I don't know why. Is a specific length preferred for strings?

+3
source share
4 answers

nvarchar stores Unicode character data, which is required if you plan on storing non-English names. If this is a web application, I highly recommend using nvarchar, even if you do not plan to be international. The disadvantage is that it consumes twice as much space, 16 bits per character for nvarchar and 8 bits per character for varchar.

+12
source

What is the best data type to use when storing strings, as the first name? I've seen used and nvarchar both used. Which one is better? Is this important?

See What is the difference between nchar (10) and varchar (10) in MSSQL?

, ASCII, nchar/nvarchar. , char/varchar .

, MS SQL Server, UTF-8. SQL Unicode ( ).

, 255, .

. , VARCHAR (255) ( )?

, ?

(, 17 VIN), .

OTOH, , , . SQL Server 900 .

+4

nvarchar , . 2GB nvarchar. 4000 , . , , .

+1

, nvarchar(n), Unicode. ( , ).

nvarchar(max), Unicode-.

, Unicode, varchar(n) varchar(max) .

, (n) 256, SQL Server 1 . , 255.

0
source

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


All Articles