搜索

软件测试数据库复习

数据库复习

创建数据库create database 数据库名 charset=utf8

使用当前数据库use 数据库名;

创建表Create table 表名字段名,类型,约束

create table student(ID int primary key auto_increment name varchar(10) ,height decimal(5,2))

插入数据insert into 表名 values(字段)

删除数据库表drop table 表名

删除数据delete from 表名 where 条件

删除表中所有数据truncate table 表名

修改数据updata 表名 set 字段名1=值,字段名2=值 where 条件;

查看所有数据库show databases

查看当前数据库中的所有表show tables

查看当前数据库select database();

查看表中数据select * from 表名;

 

模糊查询:select * from 表名 where name like ‘王%’

%代表任意多个字符)(_代表任意一个字符

范围查询(非连续范围)select * from 表名 where hometown in(’’,’’)

(连续范围)select * from 表名 where age between 12 and 20;

 

 

多表查询

1、内连接inner join on

相当于左连接和右连接的合并,会去掉所有null的数据

select * from 表一 inner join 表二 on 表一.字段=表二.字段

2、左连接left join on

左边的数据会全部被查出来,右边的数据只会查出符合on后面的条件数据

sselect * from 表一 left join 表二 on 表一.字段=表二.字段

3、右连接 right join on

右面的数据会全部被查出来,左面符合条件的数据才会显示出来

select * from 表二 right join 表一 on 表一.字段=表二.字段

4、子查询嵌入在其他查询中的select语句

select * from scores where studentNo=(select studentNo from students where name=‘王昭君’)(查询王昭君的成绩(量子查询))

 

 

分组

select 显示 from 数据源 group by 字段;(一行数据)

select 显示 from 数据源 where 条件 group by 字段

select name,age from students group by name having age >18;

(having出现前面必须有group by)

 

排序

select 显示 from 数据源  order by 字段 asc;(从小到大)

(order by必须放在where后面)

select 显示 from 数据源 where 条件 order by 字段 desc;(从大到小)

select 显示 from 数据源 order by 字段 desc limit 2;(limit数据条数)

 

© 版权声明
THE END
喜欢就支持一下吧
点赞14赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容