Data type
5 Categories: integer, numeric, character-dependent, datetime, and binary
1. Integer
| Database System |
type |
Description |
| Mysql |
tinyint [unsigned] |
A very small integer. The signed range is 128 to 127, the unsigned range is 0 to 255. |
| smallint [unsigned] |
A small integer. The signed range is 32768 to 32767, the unsigned range is 0 to 65535. |
| mediumint [unsigned] |
A medium-sized integer. The signed range is 8388608 to 8388607, the unsigned range is 0 to 16777215. |
| int [unsigned] |
A normal size integer. The signed range is 2147483648 to 2147483647, the unsigned range is 0 to 4294967295. |
| integer [unsigned] |
with int |
| bigint [unsigned] |
A large integer. The signed range is 9223372036854775808 to 9223372036854775807, the unsigned range is 0 to 18446744073709551615. |
| Oracle |
Number (10) |
There is no dedicated integer type in Oracle, so you need to use number (10) to represent the shaping. |
| DB2 |
smallint |
Small integer is a two-byte integer with a precision of 5 bits. The range of small integers ranges from 32,768 to 32,767. |
| Integer |
A generic integer is a four-byte integer with a precision of 10 bits. Large integers range from 2,147,483,648 to 2,147,483,647. |
| bigint |
The large integer is a eight-byte integer with a precision of 19 bits. The range of the giant is from 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. |
2. Values
| Database System |
type |
Description |
| Mysql |
float[(M,D)] |
Single precision floating point number. The values range from -3.402823466E+38 to -1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38. M is the number of digits that display the width, and D is a decimal. Float with no parameters or a parameter with <24 represents a single precision floating point number. |
| double[(M,D)] |
Double-precision floating-point numbers. The values range from -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. M is the display width, and d is the number of decimal digits. A double with no arguments represents a two-precision floating-point number. |
| real[(M,D)] |
Same double |
| decimal[(M[,d]) |
An uncompressed floating-point number, where the number is stored as a string, and each bit of the value uses one character. decimal point, and for negative numbers, the "-" symbol is not calculated in M. If D is 0, the value will have no decimal point or fractional part. The maximum range of decimal values is the same as double, but for a given decimal column, the actual range can be limited by the choice of M and D. If D is omitted, it is set to 0 by default. If M is omitted, it is set to 10 by default. |
| Numeric (M,D) |
Same decimal |
| Oracle |
Number (M,n) |
Numeric, M is the number of digits of all valid digits, and n is the number of digits after the decimal point. For example: Number (5,2), the maximum value for this field is 99,999, and if the value exceeds the number of digits, the extra digits are truncated. such as number (5,2), but enter 575.316 in this field in a row of data, the value that is actually saved to the field is 575.32. For example: Number (3,0), enter 575.316, the actual data saved is 575. |
| DB2 |
Decimal (P,s) |
A decimal value that is a compressed decimal number that has an implied decimal point. The compressed decimal number is stored as a BCD code. The position of the decimal point depends on the precision (p) and decimal places (s) of the number. The decimal type ranges from -1031+1 to 1031-1. |
| Numeric (P,s) |
Numeric (p,s) is a synonym for decimal (p,s). |
| Real |
Single-precision floating-point number, which is a 32-bit approximation of real numbers. The number can be zero, or within the range from -3.402E+38 to -1.175E-37 or from 1.175E-37 to 3.402E+38. |
| Double |
A double-precision floating-point number is a 64-bit approximation of real numbers. The number can be zero, or within the range from -1.79769E+308 to -2.225E-307 or from 2.225E-307 to 1.79769E+308. |
3. Character-related
| Database System |
type |
Description |
Mysql
|
CHAR (M) |
Fixed-length string, length m |
| varchar (m) |
Variable-length string with a maximum length of M |
| Tinytext |
Small variable-length string, Maximum length 2^8-1 bytes |
| Text |
Variable length large string, maximum length 216–1 bytes |
| Mediumtext |
Medium variable length string, Maximum length 224-1 bytes |
| Longtext |
Large text variable-length string with a maximum length of 232-1 bytes |
| Enum ("Value1", "value2", ...) |
Enumeration string, which can be assigned to an enumeration member |
| Set ("Value1", "value2", ...) |
A collection string that can be assigned to multiple collection members |
ORACLE
|
CHAR (M) |
Fixed-length string, length m |
| VARCHAR2 (M) |
Variable-length string with a maximum length of M |
| NVARCHAR2 (M) |
Variable-length internationalized string with a maximum length of 4GB |
| Clob |
Variable length large string, maximum length 216–1 bytes |
| Nclob |
Variable-length internationalized large string with a maximum length of 4GB |
DB2
|
CHARACTER (M) |
Fixed-length string, length m |
| VARCHAR (M) |
Variable-length string with a maximum length of M |
| LONG VARCHAR |
Variable-length strings up to 32,700 bytes long |
| Clob |
Grow the string up to 2,147,483,647 bytes long |
| Graphic[(m)] |
Fixed-length graphic string, length m, 1 double-byte characters if no length is specified |
| Vargraphic (M) |
Variable-length graphic string with a maximum length of M |
| LONG vargraphic |
Variable-length graphic strings |
4. Time and Date type
| Database System |
type |
Description |
Mysql
|
Date |
The "YYYY-MM-DD" format represents the date value. Value range: "1000-01-01" to "9999-12-31" |
| Time |
The "HH:MM:SS" format represents the time value. Value range: " -838:59:59" to "838:59:59" |
| Datetime |
The "Yyyy-mm-dd hh:mm:ss" format represents the datetime value. Value range: "1000-01-01 00:00:00" to "9999-12-31 23:59:59" |
| Timestamp |
The "YYYYMMDDHHMMSS" format represents the timestamp value. Value range: At some point in 19,700,101,000,000-2037 years |
| Year |
The year value in the "yyyy" format. Range of values: 1901 to 2155 |
ORACLE |
Date |
Date Time Data |
| Timestamp |
Time stamp |
DB2
|
DATE |
The date value. Value range: "0001-01-01 00:00:00" to "9999-12-31 23:59:59" |
| Time |
The time value. |
| TIMESTAMP |
Time stamp |
5. Binary type
| Database system |
Type |
Description |
| Mysql |
Blob |
|
| Oracle |
Blob |
|
| DB2 |
Blob |
|
Managing data tables with SQL statements
1. Create a data table
CREATE Table Table Name
(
Field name 1 field type constraint 1,
Field name 2 field type constraint 1,
Field name 3 field type constraint 1,
..................
)
For example:
CREATE TABLE t_student
(
Fnumber VARCHAR () not NULL,
FName VARCHAR () not NULL,
Fage INT not NULL,
Ffavorite VARCHAR (20),
Fphonenumber VARCHAR (20)
)
2. Define default values
CREATE TABLE T_teacher
(
Fnumber VARCHAR (20),
FName VARCHAR (20),
Fage INT,
Fismaster VARCHAR (5) DEFAULT ' NO '
)
3. Defining the primary key
CREATE TABLE T_bus
(
Fnumber VARCHAR (20),
Fdrivername VARCHAR (20),
Fusedyears INT,
PRIMARY KEY (Fnumber)
)
4. Define foreign keys
Table 1
CREATE TABLE t_department
(
FId VARCHAR (20),
FName VARCHAR (20),
Flevel INT,
PRIMARY KEY (FId)
)
Table 2
CREATE TABLE T_employee
(
Fnumber varchar, FName varchar (20),
Fdepartmentid VARCHAR (20),
FOREIGN KEY (fdepartmentid) REFERENCES t_department (FId)
)
5. Modifying an existing data table
Add Field
ALTER TABLE T_person ADD ffavorite VARCHAR
modifying fields
ALTER TABLE T_person Change fage newfage varchar (in)
Delete a field
ALTER TABLE T_person DROP Fage
6. Delete Data Sheet
DROP TABLE T_person
SQL notes-chapter II, creating and managing data tables