SQL Daten Typen Referenz
Standard und gemein SQL Daten Typen: numeric, Zeichenkette, temporal, binary, und JSON.
Numeric Types
SQL numeric types fall into exact and approximate categories. Exact types include INTEGER, BIGINT, and NUMERIC with specified precision and scale, storing values without rounding. Approximate types FLOAT and REAL use floating-point representation and may introduce rounding errors. Choosing exact types for financial calculations avoids subtle precision loss. The precision and scale of NUMERIC determine the maximum digits and decimal places stored.
- INTEGER
- Whole number, typically 32-bit
- BIGINT
- Large whole number, 64-bit
- NUMERIC(p,s)
- Exact decimal with precision and scale
- REAL
- Single-precision floating point
- DOUBLE PRECISION
- Double-precision floating point
42 9000000000 NUMERIC(10,2) 3.14 3.14159265358979 String Types
Character string types include fixed-length CHAR, variable-length VARCHAR, and text types for unbounded strings. VARCHAR with a length limit is the most common choice for bounded strings. The distinction between character and byte strings matters for multi-byte encodings: CHARACTER VARYING counts characters while BYTE VARYING counts bytes. National character types (NCHAR) were designed for Unicode but are largely superseded by UTF-8 databases.
Temporal Types
SQL temporal types include DATE for calendar dates, TIME for times, TIMESTAMP for date-time combinations, and INTERVAL for durations. TIMESTAMP WITH TIME ZONE stores an offset or zone, while WITHOUT TIME ZONE discards zone information. Storing instants in UTC and converting at display time avoids ambiguity. Interval arithmetic enables adding durations to timestamps, though time zone transitions like DST require careful handling.