Skip to content

Information Technology · Ch 3 — Relational Database Management System

Data Types in MySQL

4

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 for RollNo, quantity, age, etc.
  • DECIMAL(p, s) (also written NUMERIC(p, s)) — a fixed-point number with p total digits of which s come after the decimal point. For example, DECIMAL(8, 2) can store a value such as 123456.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 exactly n characters. If a shorter value is stored, MySQL pads it with spaces to length n. It is best when every value has the same length (for example, a state code 'OD').
  • VARCHAR(n) — a variable-length string of up to n characters. 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 form YYYY-MM-DD (for example, '2026-04-15').
  • TIME and DATETIME — a time of day, and a combined date-and-time, respectively. …
Definition 1Data type

A property of a column that fixes what kind of value it can hold (whole number, decimal, text, date, etc.) a …

Definition 2CHAR(n) vs VARCHAR(n)

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 …

Definition 3DECIMAL(p, s)

A fixed-point numeric type with p total digits and s digits after the decimal point; ideal for exact money amounts …