Difference between different string types in SQL Server?

前端 未结 9 1456
情书的邮戳
情书的邮戳 2020-12-29 04:22

What is the difference between char, nchar, ntext, nvarchar, text and varchar in SQL?

I

9条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 04:47

    Text is deprecated.

    Char is a set value. When you say char(10), you are reserving 10 characters for every single row, whether they are used or not. Use this for something that shouldn't change lengths (For example, Zip Code or SSN)

    varchar is variable. When you say varchar(10), 2 bytes is set aside to store the size of the data, as well as the actual data (which might be only say, four bytes).

    The N represents uni-code. Twice the space.

提交回复
热议问题