Skip to main content

Posts

Showing posts from 2016

SQL Server- CHAR,VARCHAR, NVARCHAR

SQL Server String Data Types CHAR CHAR is a fixed data type. So when a column is declared as CHAR, irrespective of  the actual characters stored in that variable/column, it will use all the declared space. In the above example you can see that even though the actual length of the variable is 6, It occupies 30 bytes of space.This is because when the variable @name is declared as CHAR(30), 30 bytes of space got reserved for the variable.  Also, you can observe that CHAR type column uses 1 byte of space to store each character. Summary: 1. It is a fixed data type 2. Occupies 1 byte of space for each character 3. It is used to store non-unicode character. VARCHAR VARCHAR is a variable length data type. So when a variable or column is declared as VARCHAR, irrespective of declared space, it will use only space require to store all characters. In the above example you can see that even though the declare...