Varchar - TSQL Tutorial

On Transact SQL language the varchar is part of character strings data types and have variable length. The string length must be a value from 1 through 8,000.

Varchar syntax:

varchar [ ( n ) ]
varchar [ ( max ) ]

Varchar example:

USE model;
GO
CREATE TABLE varcharTable ( a varchar(10) );
GO
INSERT INTO varcharTable VALUES ('abcdefghij');
GO
SELECT a FROM varcharTable;
GO

Results
abcdefghij

USE model;
GO
DECLARE @myVar AS varchar(20) = 'abc123';
SELECT @myVar as 'My column', DATALENGTH(@myVar) as 'Length';
GO

My columnLength
abc1236