Files
gc-plan/week4/sql/init.sql
2026-04-29 23:45:17 +08:00

38 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================
-- Week 4学生管理系统 v1 数据库初始化
-- =============================================
CREATE DATABASE IF NOT EXISTS week4_student
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
USE week4_student;
DROP TABLE IF EXISTS student;
CREATE TABLE student (
id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
name VARCHAR(20) NOT NULL COMMENT '姓名',
age INT NOT NULL COMMENT '年龄',
email VARCHAR(50) NOT NULL COMMENT '邮箱',
score INT NOT NULL DEFAULT 0 COMMENT '成绩 0-100',
avatar VARCHAR(200) COMMENT '头像文件名',
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (id),
INDEX idx_name (name),
INDEX idx_score (score)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生表';
INSERT INTO student (name, age, email, score, avatar) VALUES
('张三', 20, 'zhangsan@mail.com', 85, NULL),
('李四', 22, 'lisi@mail.com', 92, NULL),
('王五', 19, 'wangwu@mail.com', 78, NULL),
('赵六', 21, 'zhaoliu@mail.com', 88, NULL),
('孙七', 23, 'sunqi@mail.com', 95, NULL),
('周八', 20, 'zhouba@mail.com', 73, NULL),
('吴九', 22, 'wujiu@mail.com', 81, NULL),
('郑十', 21, 'zhengshi@mail.com',90, NULL);
SELECT COUNT(*) AS total_students FROM student;