Q. Differentiate between CHAR and VARCHAR datatypes.
Answer =
The difference between CHAR and VARCHAR is that of fixed length and variable length. The CHAR data type specifies a fixed length character string. When a column is given datatype as CHAR(n), then MySQL ensures that all values stored in that column have this length i.e., n bytes. If value is shorter than this length n then blanks are added, but the size of value remains n bytes.
VARCHAR, on the other hand, specifies a variable length string. When a column is given datatype as VARCHAR(n), then the maximum size a value in this column can have is n bytes. Each value that is stored in this column stores exactly as we specify it i.e., no blanks are added if the length is shorter than maximum length n. However, if we exceed the maximum length n, then an error message is displayed.
VARCHAR, on the other hand, specifies a variable length string. When a column is given datatype as VARCHAR(n), then the maximum size a value in this column can have is n bytes. Each value that is stored in this column stores exactly as we specify it i.e., no blanks are added if the length is shorter than maximum length n. However, if we exceed the maximum length n, then an error message is displayed.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )