MySQL first job---data type

Table of contents

1. Data types in MySQL

1. Text type 

2.Number type

3.Date type

 2. Create a table using multiple data types

1. Create table attributes

2. Use desc to view the specific frame of the table


1. Data types in MySQL

1. Text type 

CHAR(size) Save a fixed-length string (can contain letters, numbers, and special characters). Specify the length of the string in parentheses. Maximum 255 characters.
VARCHAR(size) Store variable-length strings (which can contain letters, numbers, and special characters). Specify the maximum length of the string in parentheses. Maximum 255 characters. Note: If the length of the value is greater than 255, it will be converted to TEXT type.
TINYTEXT Stores a character string with a maximum length of 255 characters.
TEXT Holds a character string with a maximum length of 65,535 characters.
BLOB For BLOBs (Binary Large OBjects). Stores up to 65,535 bytes of data.
MEDIUMTEXT Stores a character string with a maximum length of 16,777,215 characters.
MEDIUMBLOB For BLOBs (Binary Large OBjects). Store up to 16,777,215 bytes of data.
LONGTEXT Stores a character string with a maximum length of 4,294,967,295 characters.
LUNG BLOB For BLOBs (Binary Large OBjects). Store up to 4,294,967,295 bytes of data.
ENUM(x,y,z,etc.) Allows you to enter a list of possible values. A maximum of 65535 values ​​can be listed in an ENUM list. Inserts a null value if the inserted value does not exist in the list. Note: The values ​​are stored in the order you enter them. Possible values ​​can be entered in this format: ENUM('X','Y','Z')
SET Like ENUM, a SET can only contain up to 64 list items, although a SET can store more than one value.

2.Number type

TINYINT(size) -128 to 127 Regular. 0 to 255 Unsigned*. Specify the maximum number of digits in parentheses.
SMALLINT(size) -32768 to 32767 Regular. 0 to 65535 Unsigned*. Specify the maximum number of digits in parentheses.
MEDIUMINT(size) -8388608 to 8388607 Normal. 0 to 16777215 Unsigned*. Specify the maximum number of digits in parentheses.
INT(size) -2147483648 to 2147483647 Regular. 0 to 4294967295 Unsigned*. Specify the maximum number of digits in parentheses.
BIGINT(size) -9223372036854775808 to 9223372036854775807 Regular. 0 to 18446744073709551615 Unsigned*. Specify the maximum number of digits in parentheses.
FLOAT(size,d) Decimal numbers with floating decimal points. Specify the maximum number of digits in parentheses. Specify the maximum number of digits to the right of the decimal point in the d parameter.
DOUBLE(size,d) Large numbers with floating decimal points. Specify the maximum number of digits in parentheses. Specify the maximum number of digits to the right of the decimal point in the d parameter.
DECIMAL(size,d) A DOUBLE type stored as a string, allowing a fixed decimal point.

Note that in float(M,D), double(M,D), decimal(M,D), M must be greater than or equal to D

3.Date type

DATE() date. Format: YYYY-MM-DD Note: The supported range is from '1000-01-01' to '9999-12-31'
DATETIME() A combination of date and time. Format: YYYY-MM-DD HH:MM:SS Note: The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'
TIMESTAMP() timestamp. TIMESTAMP values ​​are stored using a description from the Unix epoch ('1970-01-01 00:00:00' UTC) to the present. Format: YYYY-MM-DD HH:MM:SS Note: The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC
TIME() time. Format: HH:MM:SS Note: The supported range is from '-838:59:59' to '838:59:59'
YEAR() Year in 2-digit or 4-digit format. Note: Allowed values ​​in 4-bit format: 1901 to 2155. Allowed values ​​in 2-bit format: 70 to 69, representing 1970 to 2069

 2. Create a table using multiple data types

1. Create table attributes

CREATE TABLE employee (
    id INT(11) comment '编号' primary key,
    iq TINYINT comment 'IQ',
    salary SMALLINT comment '薪资',
    five_plan MEDIUMINT comment '五年计划',
    code_num BIGINT comment '代码量',
    public_fee DECIMAL(2,2) comment '党费',
    team_fee FLOAT(4,2) comment '班费',
    org_fee DOUBLE(3,2) comment '团费',
    born_date DATE comment '出生日期',
    join_date DATETIME comment '入职时间',
    stamp TIMESTAMP comment '时间戳',
    clock_in_time TIME comment '打卡时间',
    leave_year YEAR(4) comment '离职时间',
    gender CHAR(2) comment '性别',
    name VARCHAR(4) comment '姓名',
    desc1 BLOB comment '描述1',
    desc2 MEDIUMBLOB comment '描述2',
    desc3 LONGBLOB comment '描述3',
    content1 TINYTEXT comment '内容1',
    content2 TEXT comment '内容2',
    content3 MEDIUMTEXT comment '内容3',
    content4 LONGTEXT comment '内容4',
    emp_ornot ENUM('yes','no') comment '是否在职',
    clockin_ornot SET('yes','no') comment '是否打卡'
)engine=InnoDB default character set utf8mb4 collate utf8mb4_0900_ai_ci;

Specify the storage engine as InnoDB, the character set as utfmb4, and the collation as utf8mb4_0900_ai_ci

2. Use desc to view the specific frame of the table

 

Guess you like

Origin blog.csdn.net/CQ17743254852/article/details/131581251