Should I store HTML as nvarchar(MAX) or ntext?

后端 未结 3 1072
太阳男子
太阳男子 2021-02-19 20:23

I don\'t know if there\'s a limit to the number of characters if I choose nvarchar(MAX), and I\'m not sure how many characters I would need anyways.

What\'s the standard

相关标签:
3条回答
  • 2021-02-19 20:42

    The default setting for NVARCHAR(MAX) is to store its text value in the table structure, unless the text is over 8,000 bytes (which is 4000 double-byte chars), at which point it behaves like an NTEXT and stores the text value in the LOB, and stores a pointer to the text in the table - which gives much worse performance.

    In short, go for NVARCHAR(4000), as long as it's OK to lose bytes over 8K long.

    0 讨论(0)
  • 2021-02-19 20:46

    The ntext type is deprecated, as are text and image. Microsoft recommends replacing them with nvarchar(max), varchar(max) and varbinary(max) respectively.

    Use nvarchar(max), therefore.

    Reference:

    • ntext, text, and image (Transact-SQL)
    0 讨论(0)
  • 2021-02-19 20:57

    The advantages of using nvarchar(MAX) are that you can run functions such as Replace, Left, Len etc on nvarchar(MAX) but not on ntext. ntext local variables also cannot be created in stored procedures however nvarchar(MAX) can.

    ntext is also likely to be deprecated in the future in favour of nvarchar(MAX) see:

    ntext, text, and image

    0 讨论(0)
提交回复
热议问题