What data types exist in SQL?
SQL has several main data types, used to store information in tables. They can be grouped as follows:
1. Numeric types
INT/INTEGER, integers, e.g. 10, 200SMALLINT, small integersBIGINT, large integersDECIMAL(p, s)/NUMERIC(p, s), exact fixed-point numbers (p is the total number of digits, s is the number of digits after the decimal point), e.g. 123.45FLOAT/REAL/DOUBLE, floating-point numbers, suited to approximate calculations
2. Character types
CHAR(n), a fixed-length string of n characters, e.g.CHAR(10)VARCHAR(n), a variable-length string up to n charactersTEXT, large text data
3. Date & Time
DATE, a date in YYYY-MM-DD formatTIME, a time, e.g. HH:MM:SSDATETIME/TIMESTAMP, a date and time togetherYEAR, a year
4. The boolean type
BOOLEAN, takes the valuesTRUE/FALSE
5. Other types
BLOB, binary data (files, images)JSON, storing data in JSON format (supported by some DBMSs, e.g. MySQL, PostgreSQL)
Put simply, a data type determines which values can be stored in a field, and affects both the memory it uses and the operations that can be performed on that data.
If you'd like, I can put together a table of every data type with examples, to make it easier for a trainee to understand and remember. Should I?
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.