常用字段设计备忘

CREATE TABLE `table_name`
(
    `uid`        INT ( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户ID',
    `username`   VARCHAR(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '登录账号',
    `password`   VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '登录密码',
    `identity`   CHAR(18) COLLATE utf8mb4_unicode_ci     NOT NULL DEFAULT '' COMMENT '身份证号码',
    `name`       VARCHAR(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '姓名',
    `sex`        TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '性别,可选值:0=未知|1=男|2=女',
    `headimgurl` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '头像图片地址',
    `year`       SMALLINT ( 4 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '年',
    `month`      TINYINT ( 2 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '月',
    `day`        TINYINT ( 2 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '日',
    `mobile`     CHAR(11) COLLATE utf8mb4_unicode_ci     NOT NULL DEFAULT '' COMMENT '手机号码',
    `email`      VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '邮箱',
    `address`    VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '地址',
    `wechat`     VARCHAR(64) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT '微信号',
    `qq`         VARCHAR(16) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT 'QQ号码',
    `ip`         CHAR(15) COLLATE utf8mb4_unicode_ci     NOT NULL DEFAULT '' COMMENT 'IP地址',
    `user_agent` VARCHAR(512) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'User Agent',
    `timestamp`  INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '时间戳',
    `balance`    DECIMAL(10, 2) UNSIGNED NOT NULL COMMENT '余额(金额),单位:元',
    `state`      TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态,可选值:0=正常|1=注销|2=冻结',
    `comment`    TEXT COLLATE utf8mb4_unicode_ci         NOT NULL COMMENT '备注(说明)',
    PRIMARY KEY (`uid`),
    UNIQUE KEY `unique:username` ( `username` ) USING BTREE COMMENT '唯一索引:登录账号'
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;



---------- 说明 ----------
-- 1、decimal(10, 2)表示最大位数为10,小数点后位数为2,需要注意的是最大位数是包含小数点后位数的,
--    也就是说decimal(10, 2)可以存储的最大值是99999999.99。

Copyright © 2024 码农人生. All Rights Reserved