As a software test engineer, we often need to operate on database data during the testing process, but most of our operations are inquiries, sometimes involving operations such as adding, modifying, deleting, etc., so we don’t actually need to operate on the database. I have a particularly in-depth understanding of the operation. The following are the more commonly used SQL statements that I have compiled during my work.
1. Insert table data:
insert into table name 1 (field 1, field 2) values (field 1 value, field 2 value);
2. Delete table data:
delete: delete from table name 1 where range (delete the qualified content in the table)
delete from table name 1 (empty the contents of the data table without releasing space, that is: the next time you insert table data, the id will continue to increase after deleting the data)
truncate: truncate table table name 1 (empty table data to release space, that is: the next time you insert table data, the id will restart from 1)
drop: drop table table name 1 (the entire table is deleted, the table must be rebuilt to use it)
3. Modify table data:
update table name 1 set field name ='new value' where range
4. Query table data:
Query data: select * from table1 where range
Total: select count (*) from table1 where range
select count (distinct (field 1) from table1 where range (distinct can be deduplicated)
Sum: select sum (field 1) from table1 where range
Average: select avg (field 1) from table1 where range
Maximum: select max (field 1) from table1 where range
Minimum: select min (field 1) from table1 where range
Sort: select * from table1 where range order by sort field name desc (desc reverse order. The default is positive order asc)
5. Complex query:
Nested query: multiple query statements are nested together to query, generally nested query statements are placed after where or having
Example:
select * from table1 where status in(select status from table2)
Multi-table join query:
table1:
table2:
(1) Inline query (inner join……on……)
select * from table1 a inner join table2 b on a.id=b.id
Query result:
(2) Left outer join……on……)
select * from table1 a left outer join table2 b on a.id=b.id
Query result:
(3) Right outer join……on……)
select * from table1 a right outer join table2 b on a.id=b.id
(4)全外联(full outer join……on……)
select * from table1 a full outer join table2 b on a.id=b.id
6.group by分组
Group statistics based on one or more list fields.
table1:
Query the highest score of each user:
select name,max(score) as max_score from table1 group by name
Query result: First group by user name, and then query to find the highest score in each group, query the
average score of each course of the whole class
select course,avg(score) as avg_score from table1 group by course
Query result: First group by courses, and then query in each group to find
the usage of average score having: same as where usage, having and group by used together. where is to filter a single record, and having is to filter grouped records (group first, then filter)
As a junior or intermediate tester, under normal circumstances, having the above database knowledge can meet most of the testing needs.
I recommend a software testing exchange group here, QQ: 642830685. The group will share software testing resources, test interview questions and testing industry information from time to time. You can actively communicate technology in the group, and the boss will ask you to answer questions. Oh.