以 blog数据库为例,来说明数据库的基础增删查改
创建数据库
-- 创建数据库create database blog;-- 使用数据库use blog;
删除数据库
-- 删除数据库drop database blog;
创建表
create table tableName()
-- 创建表create table user(id int not null auto_increment comment '',name varchar(20) not null comment '',password varchar(1000) not null comment '',primary key(id)) engine = InnoDB charset=utf8mb4;-- 查看一个数据库下的表show tables;-- 查看 blog的表结构desc blog;
删除表
-- 删除表drop table blog;-- delete 删除一条数据delete from blog where id = 2;
insert into插入数据
insert into,和 update修改数据时,必须要有 where条件约束,否则会更新所有表
-- 插入特定的字段insert into blog(title, context) values('title', 'content')-- 插入固定的数据结构,values的顺序要和表的顺序一致insert into blog values();
update修改表
update blog set title = 'new-title' where id = 2;
select查询数据
-- 查询字段select id, name from blog;-- 条件查询,查询特定 idselect id, name from blog where id = 2;-- 查询所有字段和所有数据select * from blog;-- 查询一个字段的所有数据select * from blog where id = 2;
