Information Technology · Ch 3 — Relational Database Management System
Data Types in MySQL
Data Types in MySQL
When a table is created, each attribute (column) is given a data type that decides what kind of value it can hold and how much space it takes. Choosing sensible data types is an important part of designing a good table, because it stops wrong kinds of data being stored (for example, text in a marks column). MySQL follows the standard SQL data types, of which these are the ones a Std-11 student needs:
Numeric types:
INT(integer) — whole numbers, positive or negative, with no decimal part. Suitable forRollNo, quantity, age, etc.DECIMAL(p, s)(also writtenNUMERIC(p, s)) — a fixed-point number withptotal digits of whichscome after the decimal point. For example,DECIMAL(8, 2)can store a value such as123456.78. This type is ideal for money amounts, because it keeps the decimals exact.FLOAT— an approximate (floating-point) number used for scientific or measurement values where small rounding is acceptable.
Character (text) types:
CHAR(n)— a fixed-length string of exactlyncharacters. If a shorter value is stored, MySQL pads it with spaces to lengthn. It is best when every value has the same length (for example, a state code'OD').VARCHAR(n)— a variable-length string of up toncharacters. It uses only as much space as the actual text needs, so it is the usual choice for names, addresses and other text of varying length.
Date and time types:
DATE— a calendar date, stored in the formYYYY-MM-DD(for example,'2026-04-15').TIMEandDATETIME— a time of day, and a combined date-and-time, respectively. …
A property of a column that fixes what kind of value it can hold (whole number, decimal, text, date, etc.) a …
CHAR(n) stores a fixed-length string of exactly n characters (padded with spaces if shorter); VARCHAR(n) stores a variable-length string using only the space the actual v …
A fixed-point numeric type with p total digits and s digits after the decimal point; ideal for exact money amounts …