MySql 复习及学生表,课程表,班级表的创建 | 您所在的位置:网站首页 › 学生表和成绩表的关系 › MySql 复习及学生表,课程表,班级表的创建 |
建库 create database practice; – 表示创建名字为practice的数据库 drop database practice; – 表示删除名字为practice的数据库 建表 create table 表名 ( 字段名1 数据类型, 字段名2 数据类型, 字段名3 数据类型, … … ); 向表格中增加字段 alter table 表名 add 字段名 数据类型; 实现表格中字段的改变 alter table 表名 change 旧字段名 新字段名 数据类型; 实现表格中字段的删除 alter table 表名 drop 字段名; 实现表格名称的重命名 alter table 表名 rename to 新的表名; 新增数据 insert into 表名 [(字段名1, 字段名2, …)] values (值1, 值2, …); 更改数据 update 表名 set 字段名1 = 值1 [where 条件]; 删除数据 delete from 表名 [where 条件]; 基本查询 select 字段名1, 字段名2, … from 表名; select [distinct] 字段名1 [as 别名1], 字段名2 [as 别名2], … from 表名 [where 查询条件] [group by 字段名] [having 条件] [order by 字段名1 asc或desc]; [distinct]--------去重 [as …]---------别名 [group]--------分组查询 [having 条件]-------------分组后过滤 [order by 字段名1 asc或desc];------------字段排序 between… and …、 按照条件进行模糊查询 …where first_name like ‘%拉’; 内连接: select [表名1.]字段名1, [表名2.]字段名2, … from 表名1 inner join 表名2 on 连接条件; 左外连接: select [表名1.]字段名1, [表名2.]字段名2, … from 表名1 left outer join 表名2 on 连接条件; 右外链接: select [表名1.]字段名1, [表名2.]字段名2, … from 表名1 right outer join 表名2 on 连接条件; 分页查询 |
CopyRight 2018-2019 实验室设备网 版权所有 |