文末有惊喜
为一个软件测试工程师,我们在测试过程中往往需要对数据库数据进行操作,但是我们的操作大多以查询居多,有时会涉及到新增,修改,删除等操作,所以我们其实并不需要对数据库的操作有特别深入的了解,以下是我在工作过程中整理的比较常用的SQL语句。
1.插入表数据:
insert into 表名1 (字段1,字段2) values(字段1值,字段2值);
2.删除表数据:
delete:delete from 表名1 where 范围(删除表内符合条件的内容)
delete from 表名1(清空数据表内容,不释放空间,即:下次插入表数据,id依然接着删除数据的id继续增加)
truncate:truncate table 表名1(清空表数据,释放空间,即:下次插入表数据,id从1重新开始)
drop:drop table 表名1(整张表被删除,要使用该表必须重新建)
3.修改表数据:
update 表名1 set 字段名 = ‘新值’ where 范围
4.查询表数据:
查询数据:select * from table1 where 范围
总数:select count (*) from table1 where 范围
select count (distinct(字段1) from table1 where 范围(distinct可去重)
求和:select sum (字段1) from table1 where 范围
平均:select avg (字段1) from table1 where 范围
最大:select max (字段1) from table1 where 范围
最小:sel