CBSE · 083Class XII · 2023Section B2 marks

Question 25(1)

30 March 2023 · Computer Science (083)

Differentiate between CHAR and VARCHAR data types in SQL with appropriate example.

Answer

CHAR is a fixed-length string type. Declaring CHAR(10) always reserves space for 10 characters; shorter values are padded with spaces on the right.

VARCHAR is a variable-length string type. Declaring VARCHAR(30) allows up to 30 characters but only uses the bytes needed for the actual data.

Example: To store 'India' — CHAR(20) occupies 20 bytes, whereas VARCHAR(20) occupies only about 5 bytes.

Explanation

CHAR uses fixed storage with padding; VARCHAR uses only the storage required by the actual value.