VARCHAR Length is -1 in dbeaver. Why?

a 夏天 提交于 2021-01-29 17:22:58

问题


I am using the MSSQL database and using dbeaver as a Database Manager. I found a field declared as a VARCHAR and has a length of ( -1 ) what does it stand for?

dbeaver version is 7.3.2.202101032114. the latest one


回答1:


MAX datalengths are defined as -1 in the system objects. Some applications therefore will report the length as -1, instead of MAX.

For example:

USE tempdb;
GO

CREATE TABLE dbo.TestTable (varcharColMAX varchar(MAX),
                            nvarcharColMAX nvarchar(MAX),
                            varbinaryColMAX varbinary(MAX),
                            varcharCol10 varchar(10),
                            nvarcharCol10 nvarchar(10),
                            varbinaryCol10 varbinary(10));
SELECT c.name,
       c.max_length
FROM sys.tables t
     JOIN sys.columns c ON t.object_id = c.object_id
WHERE t.[name] = 'TestTable';

DROP TABLE dbo.TestTable;

Which outputs:

name             max_length
---------------- ----------
varcharColMAX    -1
nvarcharColMAX   -1
varbinaryColMAX  -1
varcharCol10     10
nvarcharCol10    20
varbinaryCol10   10

Note that nvarcharCol10 has a length of 20 as max_length reports the size in bytes, and a single nvarchar character is 2 bytes in length (2 * 10 = 20).



来源:https://stackoverflow.com/questions/65578672/varchar-length-is-1-in-dbeaver-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!