goodk
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.nam e,
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
in the table design, I have declared
Job nvarchar(50) Checked
SELECT table_name=sysobjects.name
column_name=syscolumns.nam
datatype=systypes.name,
length=syscolumns.length
FROM sysobjects
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON syscolumns.xtype=systypes.
WHERE sysobjects.xtype='U' and sysobjects.name='AceData' and syscolumns.name='Type'
ORDER BY sysobjects.name,syscolumns
table_name column_name datatype length
AceData Type nvarchar 100
AceData Type sysname 100
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
works like a charm - thanks
but in the table width u just check whether u have 100 or not.. It is also depends on the table on the width...