数据库理论:
常见sql语句:
查询所有数据库:show databases;
创建数据库:create database 数据库名;
删除数据库:drop database 数据库名
使用数据库:use 数据库名;
创建表:create table 表名(id int,name varchar(20),sex varchar(20));
添加表数据:insert into 表名 values(1,'a','c');
添加表字段:alter table 表名 add 字段名 字段类型;
查询当前使用数据库的所有表:show tables;
查询表中的数据:select * from 表名;
查询表中的结构:desc 表名;
模糊查询:select * from 表名 where 字段名 like '%条件%;
排序查询:select * from 表名 order by 字段名 asc (升序) 默认升序
select * from 表名 order by 字段名 desc (降序)
分页查询:select * from 表名 limit m,n; 从m+1条数据开始,取n条数据
分组查询:select * from 表名 group by 条件;
五种聚合函数查询:count 计数 select count(*) from student;
sum 计算总数 select sum(*) from student;
avg 平均数 select avg(*) from student;
max 最大值 select max(*) from student;
min 最小值 select min(*) from student;
删除表:drop table 表名;
删除表单条数据:delete from 表名 where id=1;
删除表所有数据(不删除结构):delete from 表名;
删除表字段:alter table 表名 drop 字段名;
修改表数据:update 表名 set name='a',sex='b' where id=3;
修改表名称:alter table 表名 rename 修改后的表名;
修改表字段类型:alter table 表名 属性名 数据类型;