+ 1

Different between char and varchar

I know that both are used to store input string but what are some differences that everyone should keep in mind before using either datatype. I know that char is used in all the programming languages but can we use varchar in all the languages?

12th Mar 2017, 3:01 PM
Mahendra Aanjna
Mahendra Aanjna - avatar
3 Antworten
+ 4
char datatype create fixed size string. That is if short string is entered, rest of the size is padded with spaces. Moreover, while storing char data on physical storage, it occupies the space equals to the size of the char datatype. If size is not specified, char data type accepts only one character. varchar datatype also allows to store strings with the deference how it uses physical media. varchar occupies space equivalent the actual length of string rather than actually allotted to column. PS note that varchar datatype is only available in SQL databases only
12th Mar 2017, 3:30 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 2
Char is a fixed-length data type, the storage size of the char value is equal to the maximum size for this column. varchar is a variable-length data type, the storage size of the varchar value is the actual length of the data entered, not the maximum size for this column.
12th Mar 2017, 3:27 PM
Ahamad Irfan
Ahamad Irfan - avatar
+ 1
Variable length defined in Char datatype occupies that much of space in database. But In varchar we can define the limit of variable length but space occupied by the variable will of variable length. For example:- char(10) = Star (Defined variable length is 10 and used only for 4 characters, but the size occupied by this variable will be of 10) varchar(10) = Star (Defined variable length is 10 and used only for 4 characters, but the size occupied by this variable will be of 4 and rest 6 will be available for other use) Hope this will be useful!!!!
28th Mar 2017, 2:20 PM
Ananya