Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

In a table in MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by attribute A and attribute B?

a. 20,6

b. 6,20

c. 9,6

d. 6,9

Answer

Answer by student:

b. 6,20

Detailed answer by teachoo:

Let us go through each of the options and explain why they are correct or incorrect:

  • a. 20,6 . This option is incorrect because it assumes that varchar(20) always occupies 20 bytes of space, regardless of the actual value of the attribute. This is not true, as varchar only uses the space required by the value.
  • b. 6,20 . This option is correct because it correctly reflects the space occupied by varchar and char data types. Varchar only uses the space required by the value, which is 6 bytes in this case. Char always uses the maximum space defined by the data type, which is 20 bytes in this case.
  • c. 9,6 . This option is incorrect because it assumes that char(20) only occupies 6 bytes of space, which is equal to the length of the value “Meenakshi”. This is not true, as char always uses the maximum space defined by the data type.
  • d. 6,9 . This option is incorrect because it assumes that char(20) only occupies 9 bytes of space, which is equal to the length of the value “Meenakshi”. This is not true, as char always uses the maximum space defined by the data type.

The correct answer is b. 6,20 because:

  • varchar stores variable-length strings and uses the space required by the value.
  • char stores fixed-length strings and uses the maximum space defined by the data type.
  • Attribute A of datatype varchar(20) has the value “Keshav” (6 bytes).
  • Attribute B of datatype char(20) has the value “Meenakshi” (20 bytes).

So, the correct answer is b. 6,20.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo