SQL Datatypes
SQL supports various data types that allow you to specify the kind of data that can be stored in a column of a table.
These data types help enforce data integrity and provide the database with information about how the data should be stored and treated.
SQL data types:
-
Numeric Types:
- INTEGER or INT: Used for storing whole numbers.
- SMALLINT: A smaller integer type with a smaller range than INT.
- BIGINT: Used for very large integers.
- DECIMAL(p, s) or NUMERIC(p, s): Used for fixed-point numbers with a specified precision (p) and scale (s).
- FLOAT(p) or REAL: Used for approximate numeric values with a floating-point representation.
- DOUBLE PRECISION: Used for double-precision floating-point numbers.
-
Character String Types:
- CHAR(n): Fixed-length character strings with a specified length 'n'.
- VARCHAR(n): Variable-length character strings with a maximum length 'n'.
- TEXT: Used for storing large text values without a specified maximum length.
-
Date and Time Types:
- DATE: Used for storing dates in the format 'YYYY-MM-DD'.
- TIME: Used for storing times in the format 'HH:MM:SS'.
- TIMESTAMP: Used for storing date and time together.
- INTERVAL: Represents a period of time.
-
Boolean Type:
- BOOLEAN: Used to store true or false values.
-
Binary Data Types:
- BINARY(n): Fixed-length binary strings with a specified length 'n'.
- VARBINARY(n): Variable-length binary strings with a maximum length 'n'.
- BLOB: Used for storing binary large objects, such as images or files.
-
Enumerated Types:
- ENUM: A custom data type that consists of a static, ordered set of values.
-
JSON Types:
- JSON: Used for storing JSON (JavaScript Object Notation) data.
-
Geometric Types:
- POINT: Represents a point in two-dimensional space.
- LINE: Represents a straight line.
- POLYGON: Represents a closed polygon.
-
Network Address Types:
- INET: Represents an IPv4 or IPv6 host address.
- CIDR: Represents an IPv4 or IPv6 network address.
-
UUID Type:
- UUID: Used for storing universally unique identifiers.
-
Bit Strings:
- BIT(n): Fixed-length bit strings with a specified length 'n'.
- BIT VARYING(n): Variable-length bit strings with a maximum length 'n'.
-
Arrays:
- ARRAY: Used for storing arrays of values of the same data type.
-
Composite Types:
- ROW: Represents a row or record containing multiple fields of different data types.
-
User-Defined Types:
- SQL databases often allow you to define custom data types specific to your application's needs.
It's important to note that the exact set of data types and their capabilities may vary depending on the specific database system you are using (e.g., PostgreSQL, MySQL, SQL Server).
Always refer to your database system's documentation for the most accurate and up-to-date information on data types and their usage.
SQL Datatypes
Enroll Now