in the table design I have declared datalength nvarchar as 50 but the query show 100 - why?

Posted on 2011-03-20
Last Modified: 2012-05-11
I am using ms sql 8
in the table design, I have declared
Job      nvarchar(50)      Checked

    FROM sysobjects
    JOIN syscolumns ON =
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U' and'AceData' and'Type'
ORDER BY,syscolumns.colid

table_name      column_name      datatype      length
AceData      Type      nvarchar      100
AceData      Type      sysname      100
Question by:goodk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

by:Prafulla Maharjan
ID: 35175692
In vharchar u declared u declared as 50
but in the table width u just check whether u have 100 or not.. It is also depends on the table on the  width...

Accepted Solution

ssisworo earned 500 total points
ID: 35175836
use the length of the column "syscolumns.prec" information,
whereas "syscolumns.length" column is used to measure the amount of storage.

    FROM sysobjects
    JOIN syscolumns ON =
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U' and'AceData'
ORDER BY,syscolumns.colid
LVL 50

Expert Comment

ID: 35179166
nvarchar uses 2 bytes per character of storage...

so your nvarchar(50)  will actually use 100 bytes to store the data

datalength(columnname)  gives the numbers of bytes used for data by a column/expression

length(columnname) gives the number of characters used for data by the column/expression ignoring trailing spaces...

a "Varchar" datatype will also typically use and additional 2bytes to store the lenght of the data its is storing.. which is not included in the "displayed" values


Author Closing Comment

ID: 35181555
works like a charm - thanks

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question