【无标题】

发布于:2024-05-23 ⋅ 阅读:(67) ⋅ 点赞:(0)

DDL

CREATE TABLE student (
    id INT PRIMARY KEY AUTO_INCREMENT,
    createDate DATETIME NOT NULL,
    userName VARCHAR(50) NOT NULL,
    phone VARCHAR(20) NOT NULL,
    age INT NOT NULL,
    sex ENUM('男', '女') NOT NULL,
    introduce TEXT
CREATE TABLE score (
    id INT PRIMARY KEY AUTO_INCREMENT,
    scoreName VARCHAR(50) NOT NULL,
    result DECIMAL(5,2) NOT NULL,
    studentId INT,
    FOREIGN KEY (studentId) REFERENCES student(id) ON DELETE CASCADE ON UPDATE CASCADE
);

DML

INSERT INTO student (createDate, userName, phone, age, sex, introduce) VALUES
('2023-01-01 10:00:00', '张三', '13800138000', 20, '男', '喜欢阅读,学习认真'),
('2023-01-02 11:00:00', '李四', '13900139000', 21, '男', '热爱运动,性格开朗'),
('2023-01-03 12:00:00', '王五', '13700137000', 19, '女', '喜欢音乐,艺术天赋'),
('2023-01-04 13:00:00', '赵六', '13600136000', 22, '女', '热爱科学,逻辑思维强'),
('2023-01-05 14:00:00', '孙七', '13500135000', 20, '男', '勤奋好学,乐于助人');
-- 为张三(studentId = 1)插入成绩
INSERT INTO score (scoreName, result, studentId) VALUES
('数学', 85.50, 1),
('语文', 90.00, 1);


-- 为李四(studentId = 2)插入成绩
INSERT INTO score (scoreName, result, studentId) VALUES
('数学', 92.00, 2),
('英语', 88.50, 2);


-- 为王五(studentId = 3)插入成绩
INSERT INTO score (scoreName, result, studentId) VALUES
('物理', 78.00, 3),
('化学', 82.50, 3);


-- 为赵六(studentId = 4)插入成绩
INSERT INTO score (scoreName, result, studentId) VALUES
('历史', 95.00, 4),
('地理', 89.50, 4);


-- 为孙七(studentId = 5)插入成绩
INSERT INTO score (scoreName, result, studentId) VALUES
('生物', 86.00, 5),
('政治', 77.50, 5);


网站公告

今日签到

点亮在社区的每一天
去签到