Junior From PDF SQL SQL & Databases

What is the difference between CHAR and VARCHAR data types in SQL?

  • CHAR: A fixed-length string data type. It always reserves the same amount of space

regardless of the string's length.

  • Use case: When the length of the string is known and consistent.
  • VARCHAR: A variable-length string data type. It only uses as much space as needed

to store the string.

  • Use case: When the string length can vary.

Example:

CREATE TABLE Example (

fixed_char CHAR(10),

variable_char VARCHAR(10)

);

More from SQL Server Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details