I'm reading the output of the exec sp_columns
command and there are 2 columns I can't understand PRECISION
and LENGTH
I just created the following table
If I'm not mistaken, the quantity
column is a numeric INTENGER
data type, that is, this column can store a number between -2,147,483,648
and 2,147,483,647
This information is correct right?
but if i execute
exec sp_columns Books;
Precision
: I think it is the number of characters that the column allows, that is, a maximum of 10 characters between -2.1m and 2.1m
but I can't figure out why the LENGTH
column says 4.
CREATE TABLE Books
(
title VARCHAR(10), -- Maximum length up to 10 characters example 'ABCDFGHIJK'
author VARCHAR(10),-- Maximum length up to 10 characters example 'ABCDFGHIJK'
quantity INTEGER -- ?
);
exec sp_columns Books;
INSERT INTO Prueba.dbo.Books
(title,author,quantity)
VALUES
('Example A', 'A', 1),
('Example B', 'B', 12),
('Example C', 'C', 123),
('Example D', 'D', 123467890),
('Example E', 'E', 1234678901);
CodePudding user response:
What LENGTH
represents it defined in the documentation:
Column name Data type Dscription LENGTH int Transfer size of the data.1 1 For more information, see the Microsoft ODBC documentation*.
*The documentation does not contain a link to which Microsoft ODBC documentation they mean specifically, so the omission is not mine
An int
is 4 bytes in size, and hence the column has a LENGTH
of 4
defined in sys.sp_columns
.