Home > SQL Server > Get column length using Col_Length – SQL Server

Get column length using Col_Length – SQL Server


Col_Length() : This function returns the actual size of the table column in bytes. It gives us a small integer value as function output. This function returns the actual storage bytes for that column. For instance, if the column type is nvarchar(30) then it returns 60 else if smallint then it returns 2 else if varchar(max) then it returns -1. It also returns null if we do have permission to access that object or if we pass invalid argument string.

Function Syntax

COL_LENGTH ( ‘table’ , ‘column’ )

Example

Executing this function using Adventurework database objects

pic1

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: