记录建表操作
students数据库
CREATE DATABASE school;
USE `school`;
CREATE TABLE `students`(
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, -- 设置为关键字
`name` VARCHAR(20) NOT NULL,
`nickname` VARCHAR(20) NULL,
`sex` CHAR(1) NULL,
`in_time` DATETIME NOT NULL
) DEFAULT CHARSET 'UTF8'; -- 确定编码为 UTF8
USE `school`;
-- 插入语句
INSERT INTO `students` VALUES(1, '张三', '三哥', '男', now());
INSERT INTO `students` (`name`, `nickname`, `sex`, `in_time`) VALUES
('李四', '李哥', '男', now()),
('铁牛', '铁哥', '男', now()),
('苍井空', '空姐', '女', now());
-- 多个数据插入, 用逗号隔开, 注意括号要一一对应
SELECT * FROM `students`; -- 输出全部内容
SELECT * FROM `students` WHERE `sex` = '男'; -- 输出性别为男的内容
SELECT * FROM `students` WHERE `sex` = '男' ORDER BY `id` DESC; -- 以id倒叙输出
SELECT * FROM `students` WHERE `sex` = '男' ORDER BY `id` LIMIT 1, 4;
-- --LIMIT [第一条数据的索引],[本次打印数据的数量]
-- 修改
UPDATE `students` SET `sex` = '女', `nickname` = '大壮' WHERE `sex` = '男';
-- 修改所有
UPDATE `students` SET `sex` = '女', nickname = '三哥';
-- 修改性别
UPDATE `students` SET `sex` = '男' WHERE `id` < 4;
UPDATE `students` SET `sex` = '女' WHERE `id` = 4;
-- 删除
DELETE FROM `students` WHERE `sex` = '男';
增加列
alter table 表名 add column 列名 varchar(30);