This post is to detect the length of the data type of a variable and a column.
The first piece of code declares a variable, and usein sql_variant_property finds out the length of the datatype.
The second one, gets the size of the column data type of a table.
--For variable
DECLARE @test varchar(255)
SET @test = '' --Must assign a value
SELECT sql_variant_property(@test, 'MaxLength')
--For column of a table
SELECT column_name, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_name = 'myTable'
The first piece of code declares a variable, and usein sql_variant_property finds out the length of the datatype.
The second one, gets the size of the column data type of a table.
--For variable
DECLARE @test varchar(255)
SET @test = '' --Must assign a value
SELECT sql_variant_property(@test, 'MaxLength')
--For column of a table
SELECT column_name, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_name = 'myTable'
No comments:
Post a Comment