String Data Types in SQL Server with Examples

  Total Views : 460
  Comments : 0
 
  Keywords : SQL server string datatypes, Types of string datatypes in sql server with examples, Unicode character string data types, Char varchar datatypes in sql server,

Here we will learn string data types in sql server with examples and different types of string data types in sql server.

SQL String Data Types

In SQL string data types are used to store any kind of data in table. In string data types we have option like allow users to store fixed length of characters or allow them to store huge data.

 

In SQL we have different type of string data types are there those are

   

     - Character String Data Types

 

     - Unicode Character String Data Types

Character String Data Types in SQL

In character string data types we have different type of characters those are 

 

      - char datatype

 

      - varchar datatype

Char DataType in SQL Server

Char datatype which is used to store fixed length of characters. Suppose if we declared char(50) it will allocates memory for 50 characters. Once we declare char(50) and insert only 10 characters of word then only 10 characters of memory will be used and other 40 characters of memory will be wasted.

Varchar DataType in SQL Server

Varchar means variable characters and it is used to store non-unicode characters. It will allocate the memory based on number characters inserted. Suppose if we declared varchar(50) it will allocates memory of 0 characters at the time of declaration. Once we declare varchar(50) and insert only 10 characters of word it will allocate memory for only 10 characters.

 

Please check following table for more details regarding character string data types in sql server

 

Data TypeDescriptionStorage
char It’s fixed length character string and we can store maximum 8000 characters Based on defined width
varchar(n) It’s variable length character string and we can store maximum 8000 characters 2 Bytes number of characters
varchar(max) It’s variable length character string and we can store maximum 1,073,741,824 characters 2 Bytes number of characters

Unicode Character String Data Types

Generally Unicode character string data types are used in situation whenever we required to store huge data. In Unicode character string we have different type of string data types are there those are

 

    - nchar

 

    - nvarchar

 

    - nvarchar(max)

 

Please check below table for more details regarding Unicode character string data types

 

Data TypeDescription
nchar It’s fixed length character string and we can store maximum 4000 characters
nvarchar(n) It’s variable length character string and we can store maximum 4000 characters
nvarchar(max) It’s variable length character string and we can store maximum 536,870,912 characters

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User