MySQL建表语句

jasmine 于 2019-02-22 发布

先删除再建表

DROP TABLE IF EXISTS `user_account_tiktok`;
CREATE TABLE `user_account_tiktok`(
                 `itemID`      bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
                 `userID`      bigint(20) NOT NULL DEFAULT '0' COMMENT '用户ID,唯一标识',
                 `userValue`   varchar(50) NOT NULL DEFAULT '' COMMENT 'DOUYIN-UNIONID',
                 `userType`    varchar(50) NOT NULL DEFAULT '' COMMENT '用户类型(TIKTOK)',
                 `action`      tinyint(4) NOT NULL DEFAULT '0' COMMENT '删除标记',
                 `actionStamp` timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                 `createStamp` timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                 PRIMARY KEY (`itemID`),
                 KEY           `idx_userType_userValue` (`userType`,`userValue`),
                 KEY           `idx_userID` (`userID`)
             ) COMMENT='抖音用户表';

不存在再建表

CREATE TABLE IF NOT EXISTS `user_account_tiktok`  (
                 `itemID`      bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
                 `userID`      bigint(20) NOT NULL DEFAULT '0' COMMENT '用户ID,唯一标识',
                 `userValue`   varchar(50) NOT NULL DEFAULT '' COMMENT 'DOUYIN-UNIONID',
                 `userType`    varchar(50) NOT NULL DEFAULT '' COMMENT '用户类型(TIKTOK)',
                 `action`      tinyint(4) NOT NULL DEFAULT '0' COMMENT '删除标记',
                 `actionStamp` timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                 `createStamp` timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                 PRIMARY KEY (`itemID`),
                 KEY           `idx_userType_userValue` (`userType`,`userValue`),
                 KEY           `idx_userID` (`userID`)
             ) COMMENT='抖音用户表';