创建数据库
create database fss;
查询数据库
show databases;
删除数据库
drop database fss;
创建表
create table `fss`( `id` int unsigned auto_increment comment '序号', `title` varchar(20) not null comment '标题', `content` varchar(80) comment '内容', primary key (`id`))engine = InnoDB default charset = utf8;
create table `fss2`( `id` int unsigned auto_increment comment '序号', `title` varchar(20) not null comment '标题', `content` varchar(80) comment '内容', primary key (`id`))engine = InnoDB default charset = utf8;
create table `detail`(`cid` int unsigned auto_increment comment 'cid', `title` varchar(20) not null comment '标题', `press` varchar(20) not null comment '出版社', `date` varchar(20) not null comment '时间', primary key (`cid`))engine = InnoDB default charset = utf8;
查询表
show tables;
删除表
drop table fss;
插入数据
insert into fss(title, content) values('fate', 'fate grand order');
insert into fss(title,content) values('fate','fate stay night');
insert into fss(title,content) values('one piece','3D2Y');
insert into fss2(title, content) values('fate','fate zero');
insert into detail(title,press,date) values('one piece','jump','1997');
insert into detail(title,press,date) values('fate','type moon','2000');
修改数据
update fss set content = 'fate stay night' where id = '1';
删除数据
delete from fss where id = '1';
基础查询
select * from fss;
where查询
select * from fss where title = 'fata';
模糊查询(like查询)
select * from fss where title like 'fa%';
分组查询(group查询)
select * from fss group by title;
select * from fss a, detail b where a.title = b.title group by b.press;
排序查询(order查询)
select * from fss order by id desc;
union查询
select title from fss union select title from fss2;
多表查询
select * from fss a , detail b where a.title = b.title;
修改表中数据
update fss set content = 'FGO' where id = '1';
删除表中数据
delete from fss where id = '1';
修改字段
alter table fss change title title char(20) not null comment 'title';
删除字段
alter table fss drop title;
添加字段
alter table fss add title char(20) not null comment 'title';
修改表名
alter table fss2 rename fes;
创建索引
alter table fss add index title_Index (title);
alter table fss add index content_Index (conten);
删除索引
drop index content_Index on fss;
查看表中索引
show index from fss;
查看表的结构
desc fss;
事物操作
begin 开启事物
commit 提交事物
backroll 回滚
savepoint identifier 设置储存点
release savepoint identifier 删除一个储存点
backroll identifier 回滚到储存点
.....(未完)