?
Solved

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

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


SELECT table_name=sysobjects.name,
         column_name=syscolumns.name,
         datatype=systypes.name,
         length=syscolumns.length
    FROM sysobjects
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U' and sysobjects.name='AceData' and syscolumns.name='Type'
ORDER BY sysobjects.name,syscolumns.colid

table_name      column_name      datatype      length
AceData      Type      nvarchar      100
AceData      Type      sysname      100
0
Comment
Question by:goodk
[X]
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
4 Comments
 
LVL 3

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...
0
 
LVL 3

Accepted Solution

by:
ssisworo earned 2000 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.

SELECT table_name=sysobjects.name,
         column_name=syscolumns.name,
         datatype=systypes.name,
         length=syscolumns.prec
    FROM sysobjects
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U' and sysobjects.name='AceData'
ORDER BY sysobjects.name,syscolumns.colid
0
 
LVL 50

Expert Comment

by:Lowfatspread
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

0
 

Author Closing Comment

by:goodk
ID: 35181555
works like a charm - thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

777 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