CREATE TABLE `admin` ( `admin_id` int(11) NOT NULL AUTO_INCREMENT, `admin_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `admin_number` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`admin_id`) USING BTREE, )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;这段代码有什么错误,怎样改
时间: 2023-10-20 17:05:31 浏览: 136
这段代码有一个错误,即 `admin_number` 列的定义不正确。`AUTO_INCREMENT` 属性只能应用于主键列,而 `admin_number` 列不是主键列,因此不能使用 `AUTO_INCREMENT` 属性。此外,`admin_number` 列的数据类型也没有指定,应该为整数类型。
应该将代码修改为:
```
CREATE TABLE `admin` (
`admin_id` int(11) NOT NULL AUTO_INCREMENT,
`admin_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`admin_number` int(11) NOT NULL,
PRIMARY KEY (`admin_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
```
修改后的代码中,`admin_number` 列的定义变为了 `int(11) NOT NULL`,去掉了 `AUTO_INCREMENT` 属性,同时在主键定义中指定了使用 BTREE 索引算法。
相关问题
USE `sys`; DROP TABLE IF EXISTS `admin`; CREATE TABLE `admin` ( `admin_id` int(11) NOT NULL AUTO_INCREMENT, `admin_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `admin_password` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, PRIMARY KEY (`admin_id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; insert into `admin`(`admin_id`,`admin_name`,`admin_password`) values (1,'zxc','abc'),(2,'qwe','acc'); DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `user_password` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, PRIMARY KEY (`user_id`) USING BTREE, ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;这段语句的错误
这段语句有一个错误,就是在创建`user`表的语句中,最后有一个逗号,导致语法错误。正确的语句应该是:
```
USE `sys`;
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`admin_id` int(11) NOT NULL AUTO_INCREMENT,
`admin_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`admin_password` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`admin_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
INSERT INTO `admin`(`admin_id`, `admin_name`, `admin_password`)
VALUES (1, 'zxc', 'abc'), (2, 'qwe', 'acc');
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_password` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
```
CREATE TABLE `tb_admin` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', `account` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '账号', `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '密码', `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '姓名', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
这是一个创建名为 `tb_admin` 的表的 SQL 语句,表中包含了四个字段:`id`、`account`、`password` 和 `name`。其中 `id` 是主键,也是自动递增的。`account` 是账号,`password` 是密码,`name` 是姓名。这个表使用的存储引擎是 InnoDB,字符集为 utf8mb4,行格式为 Dynamic。
阅读全文