KnowledgeBoat Logo

Computer Science

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 ?

  1. 20, 6
  2. 6, 20
  3. 9, 6
  4. 6, 9

SQL Queries

1 Like

Answer

6, 20

Reason — The datatype VARCHAR(20) is a variable-length character string that can store up to 20 characters. When "Keshav" (6 characters) is assigned to attribute A with VARCHAR(20), it occupies only 6 characters of storage space because VARCHAR adjusts the space based on the actual data length. The datatype CHAR(20) is a fixed-length character string that always occupies the specified amount of space, in this case, 20 characters. When "Meenakshi" (9 characters) is assigned to attribute B with CHAR(20), it still occupies all 20 characters of storage space because CHAR pads the data with spaces to fill up the allocated space, even if the actual data is shorter.

Answered By

1 Like


Related Questions