In this chapter you will learn:
What is string data type?
Types of string data type
What is string data type?
The data type which store the value in the form of string, word or character is called string data type. There are so many string data types that are used in sql to store different string value. Here you will get string data types in the below given table.
Data types | Range | Used to store | Storage (Bytes) |
---|---|---|---|
char(n) | n characters, where n can be 1 to 8000 | Fixed length character data | n |
varchar(n) | n characters, where n can be 1 to 8000 | Variable length character data | n+2 |
text | Maximum length of 2^31-1 (2,147,483,647) characters | Character string | Variable size |
ntext | Maximum length of 2^30-1 (1,073,741,823) characters | Variable length Unicode data | Variable size |
bit | 0 or 1 | Integer data with 0 or 1 | Variable size |
image | Maximum length of 2^31-1 (2,147,483,647) bytes | Variable Length binary data to store images | Variable size |
real | -3.40E + 38 to -1.18E-38, 0 and 1.18E-38 to 3.40E + 38 | Floating Precision number | 4 |
binary | Maximum length of 8000 bytes | Fixed length binary data | n (length of data) |
varbinary | Maximum length of 8000 bytes | Variable length binary data | n (length of data) +2 |
tinytext | Maximum length of 255 characters | Character string | Variable size |
nchar | Maximum length of 4000 characters | Fixed length Unicode data | n (length of data) * 2 |
nvarchar | Maximum length of 4000 characters | Variable length Unicode data | n (length of data) * 2+2 |
varchar(max) | Maximum 1,073,741,824 characters | Variable width character string | 2 bytes + number of chars |
nvarchar(max) | Maximum 536,870,912 characters | Variable width Unicode string | Variable size |
blob | Up to 65,535 bytes of data | Binary Large OBjects | 65,535 |
mediumblob | Up to 16,777,215 bytes of data | Binary Large OBjects | 1,67,77,215 |
longblob | Up to 4,294,967,295 bytes of data | Binary Large OBjects | 4,29,49,67,295 |
mediumtext | Maximum length of 16,777,215 characters | Character string | Variable size |
longtext | Maximum length of 4,294,967,295 characters | Character string | Variable size |