1,创建数据库:create database 数据库名;
例:create database hello;
2,选择/切换数据库:use 数据库名;
例:use hello;
3,删除数据库:drop database 数据库名;
例:drop database hello;
4,创建表:create table 表名(字段名,类型,...);
例:create table hi(hey,int,...);
5,查看表结构:desc 表名;
例:desc hi;
6,查看表的定义语句:show create table 表名;
例:show create table hi;
7,删除表:drop 表名;
例:drop table hi;
8,插入数据:insert 表名 (字段1,字段2,...) values (值1,值2,...);
例:insert hi (hey) values (yes);
9,更新数据:update 表名 set 字段名 = 值 where 条件表达式;
例:update book set bookname = 'MySQL' where author = '诸葛亮';
10,删除数据:delete from 表名 where 条件表达式;
例:DELETE FROM tbl_bookinfo WHERE pupublisher = '清华大学出版社';
11,基础查询:select 字段名(*号为查询所有)from 表名;
例1:select hey from hi;
例2:select * from hi;
12,条件查询:select 字段名或* from 表名 where 条件表达式 ;
例:select * from hi where bookname = '三国演义';
13,高级查询:select 字段名或* from 表名 where 条件表达式 group by 字段名 having 条件表达式 order by 字段名 asc或desc limit 记录数;
该语句可按需使用,并非所有都要写上
解释:where(指定条件),group by (分组),order by (排序,desc为降序,asc为升序),limit(限制查询结果返回的行数),having(对分组结果进行过滤,需要搭配group by)
14,连接查询:select 字段名或* from 表1 join 表2 on 表1.字段名=表2.字段名
例:select * from table1 join table2 on table1.bye = table2.bye
15,子查询:select 字段名或* from 表名 where 字段名=(子查询)
例:SELECT * FROM tbl_bookinfo WHERE publisher IN (SELECT publisher FROM tbl_bookinfo WHERE bookname = '管理信息系统原理与实践');