SQL112. 插入记录(三)
描述
Filed | Type | Null | Key | Extra | Default | Comment |
id | int(11) | NO | PRI | auto_increment | (NULL) | 自增ID |
exam_id | int(11) | NO | UNI | | (NULL) | 试卷ID |
tag | varchar(32) | YES | | | (NULL) | 类别标签 |
difficulty | varchar(8) | YES | | | (NULL) | 难度 |
duration | int(11) | NO | | | (NULL) | 时长(分钟数) |
release_time | datetime | YES | | | (NULL) | 发布时间 |
示例1
输入:
drop table if EXISTS examination_info; CREATE TABLE IF NOT EXISTS examination_info ( id int PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID', exam_id int UNIQUE NOT NULL COMMENT '试卷ID', tag varchar(32) COMMENT '类别标签', difficulty varchar(8) COMMENT '难度', duration int NOT NULL COMMENT '时长(分钟数)', release_time datetime COMMENT '发布时间' )CHARACTER SET utf8 COLLATE utf8_bin; TRUNCATE examination_info; INSERT INTO examination_info(exam_id,tag,difficulty,duration,release_time) VALUES (9001, 'SQL', 'hard', 60, '2020-01-01 10:00:00'), (9002, '算法', 'easy', 60, '2020-01-01 10:00:00'), (9003, 'SQL', 'medium', 60, '2020-01-02 10:00:00'), (9004, '算法', 'hard', 80, '2020-01-01 10:00:00');
输出:
9001|SQL|hard|60|2020-01-01 10:00:00 9002|算法|easy|60|2020-01-01 10:00:00 9004|算法|hard|80|2020-01-01 10:00:00 9003|SQL|hard|90|2021-01-01 00:00:00
Mysql 解法, 执行用时: 35ms, 内存消耗: 6348KB, 提交时间: 2022-01-03
replace into examination_info (id,exam_id,tag,difficulty,duration,release_time) values(null,9003,'SQL','hard',90,'2021-01-01 00:00:00')
Mysql 解法, 执行用时: 35ms, 内存消耗: 6372KB, 提交时间: 2021-12-04
delete from examination_info where exam_id=9003; insert into examination_info value(null,9003,'SQL','hard',90,'2021-01-01 00:00:00');
Mysql 解法, 执行用时: 36ms, 内存消耗: 6180KB, 提交时间: 2021-12-07
replace into examination_info values(NULL,9003,'SQL','hard',90,'2021-01-01 00:00:00');
Mysql 解法, 执行用时: 36ms, 内存消耗: 6184KB, 提交时间: 2021-12-03
replace into examination_info values(NULL, 9003,'SQL','hard',90,'2021-01-01 00:00:00')
Mysql 解法, 执行用时: 36ms, 内存消耗: 6188KB, 提交时间: 2021-12-07
replace into examination_info( exam_id, tag, difficulty, duration, release_time) value(9003,'SQL','hard','90','2021-01-01 00:00:00')