In IBM DB2, there are various data types available to store different types of data. Here are some common data types in DB2 along with examples:
1. INTEGER: Signed integer with a range of -2^31 to 2^31-1.
CREATE TABLE example_table (
id INTEGER
);
2. VARCHAR: Variable-length character string with a maximum length specified.
CREATE TABLE example_table (
name VARCHAR(255)
);
3. DECIMAL: Fixed-point number with exact precision and scale.
CREATE TABLE example_table (
amount DECIMAL(10, 2)
);
4. DATE: Date value in the format 'YYYY-MM-DD'.
CREATE TABLE example_table (
birth_date DATE
);
5. TIME: Time value in the format 'HH:MM:SS'.
CREATE TABLE example_table (
check_in TIME
);
6. TIMESTAMP: Date and time value with fractional seconds precision.
CREATE TABLE example_table (
created_at TIMESTAMP
);
7. FLOAT: Floating-point number with single precision.
CREATE TABLE example_table (
price FLOAT
);
8. CHAR: Fixed-length character string with a maximum length specified.
CREATE TABLE example_table (
code CHAR(5)
);
9. BLOB: Binary large object for storing large binary data.
CREATE TABLE example_table (
image BLOB
);
10. BOOLEAN: Boolean value representing TRUE, FALSE, or NULL.
CREATE TABLE example_table (
active BOOLEAN
);
These are some commonly used data types in DB2, and they can be used to define columns in tables. Each data type has specific storage requirements and constraints that should be considered when designing database schemas.
No comments:
Post a Comment