Link to home
Start Free TrialLog in
Avatar of goodk
goodkFlag for United States of America

asked on

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

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
Avatar of Prafulla Maharjan
Prafulla Maharjan
Flag of India image

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...
ASKER CERTIFIED SOLUTION
Avatar of ssisworo
ssisworo
Flag of Indonesia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lowfatspread
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

Avatar of goodk

ASKER

works like a charm - thanks