HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlModerate

Difference between character_maximum_length and character_octet_length

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
character_octet_lengthdifferencebetweenandcharacter_maximum_length

Problem

Maybe there is an answer for this somewhere but, I couldn't find any efficient answer on Google for this question, therefore, I will ask this here.

I wanted to get some information about my Stored Procedure parameters dynamically, so I wrote this script:

SELECT  PARAMETER_NAME,
        DATA_TYPE,
        CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH
FROM    INFORMATION_SCHEMA.PARAMETERS
WHERE   SPECIFIC_NAME = @ProcName


The question is what the difference between CHARACTER_MAXIMUM_LENGTH and CHARACTER_OCTET_LENGTH. Could you give me example of when they would have different results?

Thanks in advance.

Solution

As described in the MSDN documentation CHARACTER_OCTET_LENGTH is the length in bytes, and CHARACTER_MAXIMUM_LENGTH is the length in characters.

For parameters of type char or varchar they will be the same, but for parameters of type nchar or nvarchar they will be different, with OCTET-LENGTH being twice (usually if not always) the CHARACTER_LENGTH.

Context

StackExchange Database Administrators Q#74153, answer score: 11

Revisions (0)

No revisions yet.