Page 258 - Information_Practice_Fliipbook_Class11
P. 258
Value CHAR(10) No of bytes required
'IIIT Delhi' 'IIIT Delhi' 10
'IIT Delhi' 'IIT Delhi ' 10
'IIT' 'IIT ' 10
'110016' '110016 ' 10
'29-01-2022' '29-01-2022' 10
'IIT Kharagpur' 'IIT Kharag' 10
Invalid
110016 not a string
29-01-2022 not a string
CHAR(L): Fixed-length character strings of length L.
b. VARCHAR(L): It is used for specifying variable-length character strings where L specifies the maximum length.
Unlike CHAR, VARCHAR must include a positive integer specifying the maximum allowable length of the string
as it does not use a default value. For example, declaring Emp_Name to be of type VARCHAR(25) will use one
byte more than the length of the string being stored. Thus, the string 'IIT' will require four bytes of memory.
A string longer than the defined maximum length will result in the truncation of the extra trailing characters. If any
truncated characters are not blank, SQL will raise an error.
Examples of type VARCHAR(10)
Value VARCHAR(10) string No of bytes required
'IIIT Delhi' 'IIIT Delhi' 11
'IIT Delhi' 'IIT Delhi' 10
'IIT' 'IIT' 4
'110016' '110016' 7
'29-01-2022' '29-01-2022' 11
'IIT Kharagpur' 'IIT Kharag' 11
Invalid
110016 not a string
29-01-2022 not a string
VARCHAR(L): Variable-length character strings of length upto L.
3. DATE: The data type DATE denotes a date. The standard date format is YYYY-MM-DD. However, SQL also permits
other formats like DD_MM_YYYY for storing and retrieving dates.
DATE: The standard date format is YYYY-MM-DD.
Time: The data type TIME denotes time. It supports various time formats such as
HH:MM: SS, HH-MM-SS, HH.MM AM/PM.
244 Touchpad Informatics Practices-XI

