Coding interview preparation
5.82K subscribers
459 photos
80 files
164 links
Download Telegram
SQL Question:

Query Optimization

Which query are you running and why?
8 Popular Network Protocols Explained in 1 Simple Diagram
You're giving an interview, and the interviewer asks,

What is the difference between CHAR and VARCHAR2 datatype in SQL?


Here's how you can answer:

Sample Answer:

CHAR and VARCHAR2 are both used to store text in SQL, but they work differently. CHAR is fixed-length, meaning it always uses the same amount of space no matter how short the text is. For example, if you set a column to CHAR(10) and store ‘Hi’, it will still take up 10 spaces, adding extra padding to fill the space. This can waste storage but is consistent in size.

VARCHAR2, on the other hand, is variable-length, so it only uses as much space as needed for the text. If you set a column to VARCHAR2(10) and store ‘Hi’, it only takes 2 spaces plus a little extra to store the length, saving space.

Use CHAR when your data is always the same length, like codes or short identifiers. Use VARCHAR2 when your data varies in length, like names or descriptions. CHAR can be slightly faster for fixed-length data, but VARCHAR2 is more efficient for saving space and handling different text lengths.
3
How Does HTTPS Work?
10 Types of API Testing
2
Big Data Pipelines on the Cloud
Session, JWT, SSO, and OAuth 2.0 in One Diagram
Key Database Sharding Concepts
API Security 101