Loading lesson...
INT, VARCHAR, and the lies we tell
INT, VARCHAR, and the lies we tell
Topics covered: Why data types matter, INTEGER for whole numbers, STRING types (VARCHAR), BOOLEAN for true/false, CAST for type conversion
Data types are not just labels. They fundamentally determine how your data is stored, processed, and queried. The database uses your type choice to decide everything from how much disk space to use, to whether math operations are allowed. SQL databases organize data into three fundamental categories. Every other type is a specialization of these: Type Mismatch Consequences Choosing the wrong type leads to unexpected behavior in operations like arithmetic and sorting. Arithmetic Proves the Type T
Integer literals in SQL are written as bare numbers without quotes. SQL uses quotes to distinguish strings from numbers: 42 (no quotes) is a number, while '42' (with quotes) is text. Integer Applications Integers are the most common type for IDs, counts, and any whole number data. Understanding storage size helps you choose between integer types for performance-sensitive tables. Integer types are hardware-accelerated in modern CPUs. Operations on integers run faster than equivalent operations on
String literals in SQL are enclosed in single quotes. Double quotes are reserved for identifiers (table and column names). This is a common source of confusion for beginners. Choosing String Types Different string types suit different use cases based on length variability and storage needs. One of the most common string operations is measuring how long a value is. Try it yourself. Single quotes delimit string literals in SQL while double quotes delimit identifiers like table and column names. Mi
Boolean Best Practices Choosing the right type also has real storage consequences at scale. Name boolean columns with a clear prefix like is_, has_, or can_ so readers immediately know the column holds a true/false value without reading documentation.
Practice Conversions