Software testing interview database real questions-part 1

1. What is a database?

  • Reference answer: The database is "a warehouse that organizes, stores and manages data according to the data structure. It is a collection of large amounts of data that is stored in the computer for a long time, organized, shareable, and uniformly managed.

2. What is a relational database?

  • Official definition: Relational database refers to a database that uses a relational model to organize data. It stores data in the form of rows and columns for easy understanding by users. The series of rows and columns of a relational database are called tables. A set of Tables make up a database. A user retrieves data in a database through a query, which is an executable code used to limit certain areas in the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is composed of two-dimensional tables and the relationships between them [data organization.

  • Reference answer: I understand that databases are actually divided into relational and non-relational databases. Non-relational data includes MongoDB, Google's BigTable, etc., and relational data is the database that we encounter more in our work, such as Mysql, Oracle , Sql Server, they store data in a more humane and understandable way in the form of rows and columns, these rows and columns form tables, and then the tables form libraries, and people can use the structured query language SQL to query them Query, add, delete, modify and other operations.

3. What are primary keys, foreign keys, and indexes?

  • Primary key: If a certain attribute group (note that it is a group) can uniquely identify a record, the attribute group is a primary key. The primary key cannot be repeated , and there can only be one, and it is not allowed to be empty. Primary keys are defined primarily to maintain the integrity of relational databases.

  • Foreign key: A foreign key is used to associate with another table and is a field that can determine another table record. A foreign key is the primary key of another table, which can be repeated, have multiple values, or be null . The main purpose of defining foreign keys is to maintain data consistency.

  • Index: An index is a structure that sorts the values ​​of one or more columns in a table . The advantage is to speed up the retrieval of data. The disadvantage is to slow down the speed of data entry and increase the space size of the database.

    • Which columns are suitable for indexing

      • Columns that need to be searched often, creating an index can speed up the search

      • Columns as primary keys, create indexes to enforce uniqueness

      • For columns that are often used for join queries, such as foreign keys, creating an index can speed up the join

      • The columns that often need to be searched according to the range, and the columns that often need to be sorted, plus the index, it is already sorted, then these columns are sorted, the columns searched by the specified range are also displayed in order, and the query speed will also be accelerated

      • For columns that are often used in the where clause, creating an index can speed up the judgment of the condition

    • Which columns are not suitable for indexing

      • For columns that are rarely used in queries, it is best not to add indexes, otherwise it will not only fail to speed up the query speed, but also reduce the system maintenance speed and increase space requirements

      • The value data of the column is very small, such as gender, there are only two types of male and female, there is no need to add an index

      • When the modification performance is greater than the retrieval performance, do not create indexes. They are contradictory. Adding indexes will improve the retrieval performance and reduce the modification performance.

4. What are the characteristics of Oracle, MySQL, and SQL Server?

First of all, they are all relational databases

  • Oracle: Developed by Oracle Corporation, cross-platform, safe and stable, with complex structure and high requirements for administrators, it is often used in the fields of finance and telecommunications. The sql statement is more stable and traditional, submitting data requires manual commit, and saving data is more durable.

  • MySql: Launched by MYSQLAB in Sweden, it is open source and free, small in size and fast in speed. It is suitable for small systems such as WEB websites, log management, data warehouses and embedded systems. It is more flexible for sql statements. Submitted data is automatically submitted by default, but the database restarts Updating will lose data.

  • SQL Server: Launched by Microsoft, it has better visualization, security and stability, and is suitable for enterprise-level mass data storage and query. The submitted data defaults to automatic submission, which can be set to manual. Since 2014, it also has full persistence and delayed persistence features.

5. What is SQL? What are the categories of SQL statements?

  • Official definition: Structured Query Language (Structured Query Language), referred to as SQL, is a special-purpose programming language, a database query and [programming language, used to access data and query, update and manage relational database systems.

  • Reference answer: According to my understanding, SQL is the abbreviation of Structured Query Language. Although it is called a query statement, it actually includes the manipulation function of data insertion, deletion and modification of basic tables and views, and has a strong data query function. It has three functions of data definition, data operation and data control, and includes six parts: data query language, data operation language, transaction control language, data control language, data definition language and pointer control language.

  • Classification and examples of SQL statements:

    • Data query language: select, where, order by, group by, having, etc.

    • Data manipulation language: insert, update, delete, etc.

    • Transaction control language: commit, savepoint (save point), rollback (rollback), etc.

    • Data control language: grant (authorization), revoke (recovery rights) and other control authority commands

    • Database definition language: create, drop, alter, etc.

    • Pointer control language: declare cursor, fetch into, update where current, etc. are used to operate on individual rows of one or more tables

6. What are the commonly used data types in MySQL?

In fact, software testers don't often define data types. This is the job of development, but it's best to understand.

8. Please write the basic syntax of the query table

  • Official definition: MySQL includes strict numeric data types (INTEGER, SMALLINT, DECIMAL, and NUMERIC), as well as approximate numeric data types (FLOAT, REAL, and DOUBLE PRECISION).

  • Specific size and scope:

    7. What is a constraint in a database?

  • Reference answer: Database constraints are further restrictions on the data in the table to ensure the correctness, validity and integrity of the data.

    Constraints are usually associated with a table and created using the CREATE CONSTRAINT or CREATE ASSERTION SQL statement.

    All relational databases support the use of constraints on data tables, which can better ensure the integrity of data in data tables. Constraints are validation rules enforced on a table. In addition, when data in a table is interdependent, it can protect related data from being deleted.

    Constraints generally cannot be modified.

  • Five major constraints in the database:

    • primary key constraint

      • The value of a column or a combination of several columns in the specified table is unique in the table, that is, it can uniquely specify a row of records.

      • Only one column in each table can be designated as the primary key, and columns of type IMAGE and TEXT cannot be designated as the primary key, and the specified primary key column is not allowed to have NULL attributes.

    • foreign key constraint

      • Defines the relationship between tables. When a column or a combination of columns in a table is defined the same as the primary key in other tables, you can define these columns or a combination of columns as a foreign key, and set it to be the same as which key in which table. columns are associated.

    • uniqueness constraint

      • A unique constraint specifies that a combination of one or more columns have unique values ​​to prevent duplicate values ​​from being entered in a column. Columns specified by unique constraints can have NULL attributes. Since the primary key value is unique, the primary key column can no longer set a unique constraint. A unique constraint consists of up to 16 columns.

    • check constraints

      • Check constraints set check conditions on the values ​​in the input column or the entire table to limit the input values ​​and ensure the data integrity of the database. Compound checks can be set on each column.

    • default constraint

      • A default constraint specifies a default value for a column by defining the column's default value or binding the table's column with the database's default value object. SQL Server recommends using default constraints instead of defining default values ​​to specify default values ​​for columns.

  • The most basic query statement:

    select <column name 1>, <column name 2>... from <table name>;

  • Query statement with condition:

    select <column name 1>, <column name 2>... from <table name> where condition;

  • Example: Take the score sheet as an example

1) Query the name and grades in the score table scores

select stuName as 姓名,stuScore as 成绩 from scores;  --as是起别名,为了可读性强,如果不需要,则只需要select stuName,stuScore from scores;
 
 

2) Query all columns of the scores table

select  *  from scores;

 

  • 3) Delete duplicate data when querying (scores table), such as querying by score data, delete duplicate data, and two 88 will be deduplicated

select distinct stuScore from scores;

 

 

4) Conditional query (scores table), for example: Find out the scores of students whose scores are greater than 90 or whose names contain the word "Guang"

select * from scores where stuScore >= 90 or stuName like '%广%';

The conditions here need to use comparison operators, logical operators and string fuzzy queries

To sum up, refer to the answer: the most basic syntax of a query statement is select * from table name. If there are not many column names and no special requirements, I usually use numbers to find out all of them. If there are too many column names, and I only need to check a few columns of data, I will replace the * with the corresponding list. If the meaning of the list word is not obvious, I will also use the as keyword to make an alias, check The data that come out are clear at a glance. Then, if the demand is to check more specific data that meets a certain condition, I will add the keyword where, and then bring the required conditions. For example, to check a student's grade table, you need to check the grades of students who have passed or above, that is, select * from score table where score>=60, according to different needs, arithmetic operators, comparison operators, logical operators, string fuzzy queries, etc. may be used.

9. What is a subquery? What are the categories of subqueries?

  • Reference answer: A subquery is a query that uses the result of one query (subquery) as the data source or judgment condition of another query (main query). Common subqueries include WHERE subquery, HAVING subquery, FROM subquery, SELECT subquery, EXISTS subquery, and subqueries should use parentheses ();

  • where subquery

    • Include another layer of query in the where clause, for example: query the student information (scores table) whose score is lower than the average score

select * from scores where stuScore < (select avg(stuScore) from scores);

 

having subqueries

The HAVING clause is a clause for filtering group statistics functions, and subqueries can also be used in the HAVING clause, for example: query the students with the highest average score and their average scores (scores2 table)

select stuName,score_avg from socres2 group by stuName having score_avg = (select max(score_avg) from socres2);

 

from subquery

The FROM subquery is to use a query structure (generally multiple rows and multiple columns) as the data source of the main query, for example: query the students whose average score is higher than 90 and the average grade of the student

 

select stuName,score_avg from (select stuName,score_avg from socres2 group by stuName) stu_score where stu_score.score_avg>90; 

select subquery

  • The SELECT subquery uses the result of the query in the SELECT clause (usually used with the dual empty table), for example: the proportion of students with an average score of more than a pass in the total number of students

select (select count(*) from socres2 where score_avg>=60)/(select count(*) from socres2) as 比例 from dual;

 

 

exit subquery

Bring the data of the main query to the subquery for verification, and return true if successful, otherwise return false. If the main query receives true, it will display all the data that meets the conditions, and if it receives false, it will not display anything. For example: query information based on the condition of "if there are students who fail"

select * from socres2 where exists (select * from socres2 where score_avg < 60)

 

 

Guess you like

Origin blog.csdn.net/shuirongwu/article/details/130235285