SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT ''
时间: 2024-09-03 15:03:27 浏览: 65
这是一段 SQL 设置语句,主要用于设置字段的数据格式和默认值。具体来说:
- `SET` 开始了一个设置声明,通常用于改变数据库对象(如表字段)的属性。
- `utf8mb4` 是字符集,表示使用 UTF-8 编码的变长字符集,支持更多种语言和字符。
- `COLLATE utf8mb4_general_ci` 是排序规则,这里的 "general_ci" 是一种 case-insensitive (不区分大小写的) 比较规则。
- `NULL` 表示该字段可以接受 NULL 值。
- `DEFAULT ''` 指定当新记录插入时,如果没有明确指定值,则默认为空字符串 ''。
总的来说,这段设置告诉数据库,该字段将采用 UTF-8 编码,允许 NULL 值,并且默认情况下其值为空字符串,且对于大小写不敏感的文本比较。
相关问题
把这段代码改为doris的建表语句CREATE TABLE `aa_ccd` ( `ID` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `CCDCODE` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ICNNAME` varchar(107) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ISDISEASE` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ENNAME` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `PARENTID` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `YEAR` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `NOTE` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEFTSPACE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LIMITED` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL1` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL2` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL3` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL4` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, PRIMARY KEY (`ID`) USING BTREE, INDEX `index1`(`CCDCODE`) USING BTREE, INDEX `index2`(`ICNNAME`) USING BTREE, INDEX `index_yes`(`YEAR`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
您好!以下是将代码改为Doris建表语句的结果:
CREATE TABLE aa_ccd (
ID VARCHAR(20),
CCDCODE VARCHAR(20),
ICNNAME VARCHAR(107),
ISDISEASE VARCHAR(20),
ENNAME VARCHAR(20),
PARENTID VARCHAR(20),
YEAR VARCHAR(4),
NOTE VARCHAR(200),
LEFTSPACE VARCHAR(10),
LIMITED VARCHAR(4),
LEVEL1 VARCHAR(4),
LEVEL2 VARCHAR(4),
LEVEL3 VARCHAR(4),
LEVEL4 VARCHAR(4)
) DISTRIBUTE BY HASH(ID) BUCKETS 8 PROPERTIES("replication_num"="1");
DROP TABLE IF EXISTS `aa_ccd`; CREATE TABLE `aa_ccd` ( `ID` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `CCDCODE` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ICNNAME` varchar(107) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ISDISEASE` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `ENNAME` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `PARENTID` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `YEAR` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `NOTE` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEFTSPACE` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LIMITED` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL1` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL2` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL3` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `LEVEL4` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, PRIMARY KEY (`ID`) USING BTREE, INDEX `index1`(`CCDCODE`) USING BTREE, INDEX `index2`(`ICNNAME`) USING BTREE, INDEX `index_yes`(`YEAR`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 这个建表sql在doris数据库执行时报错,[SQL] Query doris_2 start [ERR] 1105 - errCode = 2, detailMessage = Syntax error in line 25: `id` varchar(50) CHARACTER SET utf8mb4 COLLAT... ^ Encountered: CHARACTER Expected: COMMA [ERR] 这是为什么
根据报错信息,可以看到是在第25行出现了语法错误,缺少了逗号。具体来说,是因为在第24行的最后缺少了一个逗号,导致第25行的语句被解析为一个新的字段,而不是原本的字段属性。因此,应该在第24行最后加上逗号,即在 `LEVEL4` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL 后面加一个逗号,就可以解决这个问题了。
阅读全文