हिंदी

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

Advertisements
Advertisements

प्रश्न

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

अंतर स्पष्ट करें
Advertisements

उत्तर

S. No. CHAR VARCHAR
1. Used to store strings of fixed size. Used to store strings of variable length.
2. Uses a fixed amount of storage, based on the size of the column. Use varying amounts of storage space based on the size of the string stored.
3. Takes up 1 to 4 bytes for each character, based on the collation setting. Takes up 1 to 4 bytes for each character based on the collation and requires one or more bytes to store the length of the data.
4. Better performance. Slightly poorer performance because length has to be accounted for.

Example: Consider the table student given below:

Table: Student
Roll Name Phone Aadhar Marks

Every value in the Name field will take up 30 characters if the user selects char(30), regardless of whether "Ria" or "Ramakrishnan Ayyar" is the saved name.

If varchar(30) is used, "Ria" will occupy 3 units, whereas "Ramakrishnan Ayyar" will take 18 units.

shaalaa.com
Data Types and Constraints in MySQL
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×