In SQL, data types define the type of data that can be stored in a column. Here are some common SQL data types:
img
Numeric Data Types
INT: Integer values.
- Example:
INT
,INTEGER
- Example:
FLOAT: Floating-point numbers.
- Example:
FLOAT
,DOUBLE
- Example:
DECIMAL: Fixed-point numbers, useful for storing exact numeric values.
- Example:
DECIMAL(10, 2)
(10 digits in total, 2 after the decimal point)
- Example:
SMALLINT: Smaller integer values.
- Example:
SMALLINT
- Example:
BIGINT: Larger integer values.
- Example:
BIGINT
- Example:
Character String Data Types
CHAR: Fixed-length character strings.
- Example:
CHAR(10)
(10 characters)
- Example:
VARCHAR: Variable-length character strings.
- Example:
VARCHAR(255)
- Example:
TEXT: Large variable-length character strings.
- Example:
TEXT
Date and Time Data Types
DATE: Date values.
- Example:
DATE
(format:YYYY-MM-DD
)
- Example:
TIME: Time values.
- Example:
TIME
(format:HH:MM:SS
)
- Example:
DATETIME: Date and time values.
- Example:
DATETIME
(format:YYYY-MM-DD HH:MM:SS
)
- Example:
TIMESTAMP: Date and time values, typically used for tracking changes in records.
- Example:
TIMESTAMP
(format:YYYY-MM-DD HH:MM:SS
)
- Example:
Boolean Data Type
- BOOLEAN: Stores
TRUE
orFALSE
.- Example:
BOOLEAN
- Example:
Binary Data Types
BINARY: Fixed-length binary data.
- Example:
BINARY(10)
- Example:
VARBINARY: Variable-length binary data.
- Example:
VARBINARY(255)
- Example:
BLOB: Large binary objects.
- Example:
BLOB
- Example:
Other Data Types
ENUM: Enumeration, a string object that can have one value chosen from a list of permitted values.
- Example:
ENUM('small', 'medium', 'large')
- Example:
SET: A string object that can have zero or more values, each chosen from a list of permitted values.
- Example:
SET('a', 'b', 'c')
- Example:
These are some of the most commonly used data types in SQL. Different SQL database systems may have additional data types or slight variations in the names and specifications of these data types.
- Get link
- X
- Other Apps