NVARCHAR(MAX)可以存储多少长度?

时间:2019-05-22 16:06:10

标签: sql-server

我有一个表,其中捕获了API返回的响应。响应是来自API的异常。响应本质上是故障异常。

“响应”列的数据类型为NVARCHAR(MAX)。我对响应的长度进行了查询。

SELECT Len(Request) as [Request Length], Len(Reponse) as [Response length] from SpiderDealioSvc_ErrorLog

查询的结果是:-

Request Length  Response length
3152    212
3152    212
2953    5101
2953    5101
2953    5101

我的问题是假设Response为20000,NVARCHAR(MAX)会接受它还是出现错误或问题。 NVARCHAR可以采用的最大长度是多少。

我还粘贴了响应字符串:-

{
  "Fault": {
    "faultcode": "a:DeserializationFailed",
    "faultstring": {
      "lang": "en-US",
      "TEXT": "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:deal. The InnerException message was 'There was an error deserializing the object of type DealioCapLinkLib.Dealio.Models.Deal. The value '2.333333333E9' cannot be parsed as the type 'decimal'.'.  Please see InnerException for more details."
    },
    "detail": {
      "ExceptionDetail": {
        "HelpLink": "",
        "InnerException": {
          "HelpLink": "",
          "InnerException": {
            "HelpLink": "",
            "InnerException": {
              "HelpLink": "",
              "InnerException": "",
              "Message": "Input string was not in a correct format.",
              "StackTrace": "   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)\r\n   at System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider)\r\n   at System.Xml.XmlConvert.ToDecimal(String s)\r\n   at System.Xml.XmlConverter.ToDecimal(String value)",
              "Type": "System.FormatException"
            },
            "Message": "The value '2.333333333E9' cannot be parsed as the type 'decimal'.",
            "StackTrace": "   at System.Xml.XmlConverter.ToDecimal(String value)\r\n   at System.Xml.ValueHandle.ToDecimal()\r\n   at System.Xml.XmlBaseReader.ReadContentAsDecimal()\r\n   at System.Xml.XmlDictionaryReader.ReadElementContentAsDecimal()\r\n   at ReadDealFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )\r\n   at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)\r\n   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)\r\n   at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)\r\n   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)\r\n   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)",
            "Type": "System.Xml.XmlException"
          },
          "Message": "There was an error deserializing the object of type DealioCapLinkLib.Dealio.Models.Deal. The value '2.333333333E9' cannot be parsed as the type 'decimal'.",
          "StackTrace": "   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)\r\n   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)\r\n   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)",
          "Type": "System.Runtime.Serialization.SerializationException"
        },
        "Message": "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:deal. The InnerException message was 'There was an error deserializing the object of type DealioCapLinkLib.Dealio.Models.Deal. The value '2.333333333E9' cannot be parsed as the type 'decimal'.'.  Please see InnerException for more details.",
        "StackTrace": "   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)\r\n   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)\r\n   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)\r\n   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)\r\n   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)\r\n   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)\r\n   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)\r\n   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)\r\n   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)\r\n   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)",
        "Type": "System.ServiceModel.Dispatcher.NetDispatcherFaultException"
      }
    }
  }
}

2 个答案:

答案 0 :(得分:2)

nvarchar(MAX)最多可以存储2GB字符。 nvarchar中的每个字符均为2个字节。 2GB是2,000,000,000字节,因此nvarchar(MAX)可以存储2,000,000,000 / 2个字符= 1,000,000,000个字符。

因此,回答您的问题“ nvarchar(MAX)中可以容纳20,000个字符吗?”:是的,您可以(50,000次)。

答案 1 :(得分:1)

NVARCHAR(MAX)最多可以处理2GB。如果您使用的是varchar(每个字符1个字节),那将为您提供约2B个字符,但是由于您使用的是nvarchar(每个字符2个字节),因此可以存储约1B个字符。

来源(msdn):enter link description here