1.创建数据库:create DATABASE 数据库名 CHARACTER set utf8; 不用utf8,在输入中文时会乱码。 2.查看数据库:show create database 数据库名。 3.删除数据库:drop database 数据库名; 4.进入数据库:use 数据库名; 5.查看表结构:desc 表名; 6.查看创建表结构:show create table 表名; 7.删除表:drop table 表名; 8.添加字段:alter table student add 字段 类型(长度); 9.删除字段:alter table student drop 字段; 10:修改字段:alter table student MODIFY 字段 类型(长度); 11:新增数据一条:INSERT into student values (字段值,字段值,,,,); 12:多条:INSERT into student values (字段值,字段值,,,,),(字段值,字段值,,,,),(字段值,字段值,,,,); 13:修改一条数据中的一个字段:update 表名 set 字段=新值 where 条件; 14.修改一条数据中的多个字段:update 表名 set 字段=新值,字段=新值 where 条件; 15.删除一条数据:delete from student where 条件; 16.删除表中全部数据:delete from student ; 17.查询全部信息:select * from student; 18.查询一条信息:select * from student where sname = ‘’; 19.条件查询:select * from student where sid = 1 or sid = 3; select * from student where sid in(1,3); 20.条件查询:select * from student where sscore > 50 and sscore < 90; select * from student where sscore BETWEEN 50 and 90; 21:模糊查询:select * from student where sname like ‘哈%’; select * from student where sname like ‘%哈’; select * from student where sname like ‘%哈%’; 22.排序(倒序):select * from student ORDER BY sscore desc; 23.分页:select * from student limit 1,2; 24.分组:select count(*),ssex from student GROUP BY ssex HAVING 条件 25.聚合数据:count()/avg()/min()/max()/sum()
|