Length of column with 'text' data type

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Length of column with 'text' data type

    Hi. I'm getting various data about columns in a table by using sp_column.
    Everything is working as I expected, except one thing. When I get the length of
    a column that is of data type 'text', it returns the number 2147483647 when it
    is supposed to return 16. I've played around with this number, and I can't seem
    to find any relationship, mainly because it is prime. Is there some way I can
    get the actual length of the table?

    Blazeix Guest

  2. Similar Questions and Discussions

    1. Filter table by column data type
      Hello everyone, I'm using VB Script, SQL 2K. Is it possible to create a recordset from a table based on the column data type? Hypothetically,...
    2. #38805 [NEW]: PDO Truncates Text from SQL Server Text Data Type Field
      From: gkrajci at arescorporation dot com Operating system: Windows NT PBMA-WB2 5.2 build 37 PHP version: 5.1.6 PHP Bug Type: ...
    3. Detect CFQuery Column Data Type
      Is it possible to detect the data type of a column in an ODBC Select CFQuery with MS Access or SQL Server? This solution will save me a lot of...
    4. Using DataFormat to limit length of text in column?
      Hi! If I have a column in a datagrid, that contains text (possibly a lot of text) and I only want to display the first 50 chars, can I use...
    5. #25644 [NEW]: xsl:sort with data-type='text' ... php crashes
      From: sparky_industries at mad dot scientist dot com Operating system: Windows 98 PHP version: 4.3.3 PHP Bug Type: XSLT...
  3. #2

    Default Re: Length of column with 'text' data type

    The Text datatype has a maximum length of 231-1 (2,147,483,647) characters.
    That should be what the sp_columns is telling you. The DATALENGTH() function
    should return the length of a specific text, if that's what you're after.

    JaredJBlackburn Guest

  4. #3

    Default Re: Length of column with 'text' data type

    I'm not sure why you would expect 16. Take a look at SQL Server Books Online
    for the text datatype:

    text

    Variable-length non-Unicode data in the code page of the server and with a
    maximum length of 231-1 (2,147,483,647) characters. When the server code
    page uses double-byte characters, the storage is still 2,147,483,647 bytes.
    Depending on the character string, the storage size may be less than
    2,147,483,647 bytes.


    It looks to me like sp_columns is reporting exactly what I would expect it to.

    Phil



    paross1 Guest

  5. #4

    Default Re: Length of column with 'text' data type

    @@TEXTSIZE should give you the current setting for the max size of a text.

    SET TEXTSIZE sets or changes that setting.
    JaredJBlackburn Guest

  6. #5

    Default Re: Length of column with 'text' data type

    [q]Originally posted by: paross1
    I'm not sure why you would expect 16.[/q]

    Well, I'm using SQL Server Enterprise, and when I specify that a column is
    'text' it automatically sets the column length to 16. But if 2^31-1 is actually
    the length, I guess i'll stick to that. Thanks for everyone's help.

    Blazeix Guest

  7. #6

    Default Re: Length of column with 'text' data type

    It looks like you are confusing the length the data in a column with the length
    of the data type. Since individual text data type values can be too long to
    store in a single data row, they are stored in a collection of pages separate
    from the pages holding the data for the other columns of the row. When that is
    the case, all that is stored in the data row is a 16-byte pointer. For each
    row, this pointer points to the location of the text data.

    What Enterprise Manager is reporting as "length" is the length of the pointer
    that actually points to the location where the data is actually stored.

    Phil

    paross1 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139