编辑代码

CREATE DATABASE example_db;
USE example_db;
CREATE TABLE students (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT,
    gender ENUM('Male', 'Female', 'Other'),
    class VARCHAR(20),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO students (name, age, gender, class) VALUES
('Alice', 20, 'Female', 'Class A'),
('Bob', 22, 'Male', 'Class B'),
('Charlie', 21, 'Other', 'Class A'),
('Diana', 19, 'Female', 'Class C');
SELECT * FROM students;
-- 创建数据库
CREATE DATABASE example_db;

-- 使用数据库
USE example_db;

-- 创建数据表
CREATE TABLE students (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT,
    gender ENUM('Male', 'Female', 'Other'),
    class VARCHAR(20),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 插入数据
INSERT INTO students (name, age, gender, class) VALUES
('Alice', 20, 'Female', 'Class A'),
('Bob', 22, 'Male', 'Class B'),
('Charlie', 21, 'Other', 'Class A'),
('Diana', 19, 'Female', 'Class C');

-- 查询数据
SELECT * FROM students;