问题
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