当前位置:网站首页>Database common interview questions are ready for you
Database common interview questions are ready for you
2022-06-12 09:13:00 【Software testing Lao Mo】
Catalog
(1) The operation of the table
(2) What is database constraint , What are the common constraints ?
(3) The difference between primary key and foreign key ?
(4) What is index ? Advantages and disadvantages ?
(5)order by and group by The difference between ?
(6)sql What are the connection methods of the tables in ?
(7) Query statements in the database is slow , How to optimize ?
(9) How to delete the main table record , Delete the records associated from the table ?
(10) List several common aggregate functions ?
(12)oracle and mysql The difference between ?
(13)union and union all What's the difference ?
(14)truncate and delete The difference between ?
(15) Transfer line column 、 How to turn a column into a line ?
(16)oracle How to go heavy ? How to get system time ?
(18) What is stored procedure ? Advantages and disadvantages of stored procedures ?
(19) The difference between stored procedures and functions ?
(1) The operation of the table
The creation of a table :create table Table name ( Name 1 type constraint , Name 2 type constraint ...)
The deletion of the table :drop table Table name
Table changes :alter table Table name add|drop Name | Constraint name
insert record :insert into Table name ... value...
Update record :update Table name set Name = value where Conditions
Delete record :delete from Table name where Conditions
Query log :select Name ... from Table name where Conditions
(2) What is database constraint , What are the common constraints ?
Constraints can be divided into : Primary key constraint primary key、
Foreign key constraints foreign key、
Unique constraint unique、
Check constraint check、
NULL constraint not null、
Default constraint default
(3) The difference between primary key and foreign key ?
The primary key is unique in this table , Can't be empty , Foreign keys can be repeated and can be empty .
The foreign key is associated with the primary key of another table , Cannot create a foreign key that does not exist in the corresponding table .
(4) What is index ? Advantages and disadvantages ?
A structure that sorts the values of one or more columns in a database table , Use indexes to quickly access specific information in database tables .
Advantages and disadvantages : advantage : Using index can speed up the retrieval of data , Index can be unique , Creating an index allows you to specify a single column or multiple columns
shortcoming : Slow down the data entry speed , It also increases the size of the database
(5)order by and group by The difference between ?
order by Query for sorting 、
ASC Ascending DESC Descending
group by Query for groups 、
having It can only be used for group by Clause 、 Act on the group 、
having The query statement of condition clause needs to use aggregate function
(6)sql What are the connection methods of the tables in ?
Internal connection 、 External connection 、 Cross connect
Internal connection :inner join in , A combination of two tables
External connection : Divided into left connection 、 The right connection 、 Full connection
Left connection A left(outer) join B
With A Table based ,A All the data in the table ,B There are combinations of watches , What is not is null
The right connection A right(outer) join B
With B Table based ,B All the data in the table ,A There are combinations of watches , What is not is null
Full connection A full(outer) join
The two watches are the same ,A Table has ,B Data not in the table ( Is shown as null), Again B Table has ,A What the table doesn't show is null
Cross connect :cross join, Even if Descartes product
(7) Query statements in the database is slow , How to optimize ?
① Index
② Reduce the association between tables
③ Optimize sql sentence , Try to make sql Quickly locate the data , Don't let sql Do a full table query , We should take the index , Put the large amount of data in the front
④ Simplify query fields , Useless fields do not
⑤ As far as possible with PreparedStatement To query , Do not use Statement
(8) What is a cursor ?
A cursor is a mechanism that can extract one record at a time from a result that includes multiple data records for processing .
How to use the cursor :① Define cursors declare cursor Cursor name for select Query statement [for {readonly|update}]
② Open cursor open cursor
③ Manipulating data from cursors fetch... current of cursor
④ Close cursor close cursor
(9) How to delete the main table record , Delete the records associated from the table ?
If there is a primary foreign key relationship between the two tables , When deleting the records of the primary key table , If there is an associated record from the table, the deletion will fail
When defining foreign key constraints , You can specify at the same time 3 Delete strategies : One is to delete the record from the table ( cascading deletion );
Second, set the foreign key field of the slave table record to NULL;
(10) List several common aggregate functions ?
sum function avg function max function min function count function
(11)oracle Basic data type ?
① String type char 、nchar 、 varchar 、 vachar2
② Numeric type number 、 integer
③ Floating point type float
④ The date type date 、 timestamp
⑤ LOB type blob 、 clob 、 nclob 、 bfile
(12)oracle and mysql The difference between ?
① Library functions are different
② oracle It's managed with tablespaces ,mysql No
③ Show all current tables 、 user 、 Change connected users 、 Show current connected users 、 Different statements for executing external scripts
④ In paging query ,mysql use limit ;oracle use rownum
(13)union and union all What's the difference ?
union Filter duplicate records after table join , So after the table is joined, the resulting result set will be sorted , Delete duplicate records and return results
union all Just simply merge the two results and return
In terms of efficiency ,union all Than union Much faster , therefore , If you can confirm that the two result sets of the merge do not include duplicate data , So use union all
(14)truncate and delete The difference between ?
The same thing : Both delete all rows in the table
Different places :① truncate table Than delete Fast
② delete Delete one line at a time , And record one entry for each Deleted Row in the transaction log ;truncate Delete data by releasing the data page used to store the data , And only record the release of the page in the transaction log .
③ truncate table Delete content , Free space without deleting definition
④ delete table Delete content , Don't delete definition but don't free space
⑤ drop table Delete content and definition , Release space
(15) Transfer line column 、 How to turn a column into a line ?
① Use decode function
② Use case when sentence
(16)oracle How to go heavy ? How to get system time ?
duplicate removal : Use distinct keyword select distinct name from A
Get system time :select to_char(sysdate, 'yyyy-MM-dd HH24:mi:ss') from dual;
(17) The role of sequence ?
oracle Use sequences to generate unique numbers , It is used to process an auto increment field in a table .
Once you access a serial number ,oracle Will automatically increment the next number before processing the next request , This ensures that there are no duplicate values .
(18) What is stored procedure ? Advantages and disadvantages of stored procedures ?
Stored procedure a precompiled sql sentence , The advantage is to allow modular design
That is to say, you only need to create , Later in the program can be called many times , If an operation needs to be performed more than once sql, Using stored procedures is better than just sql Statement execution should be fast .
Advantages and disadvantages of stored procedures :
advantage :① Stored procedures are precompiled , High execution efficiency
② Stored procedure code is stored in the database , Call... Directly through the stored procedure name , Reduce network communication .
③ High safety , The execution of a stored procedure requires a user with certain permissions
④ Stored procedures can be reused , Can reduce the workload of database developers
shortcoming : Poor portability
(19) The difference between stored procedures and functions ?
① Function has return value , The stored procedure did not return a value
② Because the stored procedure does not return a value , So we can't assign the execution result of stored procedure to variable ; Function has return value type , When you call a function , You can assign the execution result of a function to a variable .
That is to say , The function can be in select Use in statement , Stored procedures can't .
Here are some sql Sentence practice :
-- Check the math scores of all the students
select s.name,g.score
from student s, grade g
where s.id=g.id and g.kemu=' mathematics ';
-- Count the total score of each student , Show fields : full name 、 Total score
select a.name sum(b.score) as sum_score
from student a, grade b
where a.id = b.id group by name;
-- List the best students in each course , Request fields : Student number 、 full name 、 subject 、 achievement
select a.id, a.name, g.kemu, max(g.score)
from student a, grade g
where a.id = g.id group by g.kemu
-- List the top three students in math
select a.id, a.name, g.kemu, g.score
from student a, grade g
where g.score = ' mathematics ' order by score limit 3;
-- Statistics English class is less than 80 Divided people
select a.id, a.name, g.kemu, g.score
from student a, grade g where a.id g.id
and g.kemu = ' English ' orader by g.score <80;
-- Check the top two in each subject
select a.id , a.name, g.kemu, g.score
from student a, grade g
where a.id = g.id
order by g.kemu limit 2;

Thank everyone who reads my article carefully !!!
If you can use the following information, you can take it away directly :
1、 Self study development or test the necessary complete project source code and environment
2、 Test all templates in the work ( test plan 、 The test case 、 Test report, etc )
3、 Classic interview questions for software testing
4、Python/Java Automation test practice .pdf
5、Jmeter/postman Interface test full set of video acquisition
I personally sorted out some technical materials I have sorted out in my software testing career in recent years , contain : e-book , Resume module , Various work templates , Interview treasure , Self study projects, etc . You can come to me if you need
边栏推荐
- Oracle personal replication (I)
- Jupyter notebook sets the default browser to open with an error syntaxerror: (Unicode error) 'UTF-8' codec can't decode byte 0xd4
- Sword finger offer II 016 Longest substring without repeating characters - sliding window
- 解压缩zip文件的工具类
- (JS) three digits are separated by commas, and two decimal places are reserved (or rounded)
- MFS explanation (IV) -- MFS management server installation and configuration
- ABC253F Operations on a Matrix
- Cas d'essai et spécification de description des bogues référence
- Swagger documentation details
- 更改tabledata列名
猜你喜欢

Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?

EIP-1559
APP测试面试题汇总,面试必考一定要看

Distributed transaction solution 1: TCC (compensation transaction)

Minimum transfer times
自动化测试学习路线,快来学吧

MySQL installation

Distributed task scheduling

2022 low voltage electrician retraining question bank and online simulation examination

网页中加载二次元3D虚拟主播源码(1:项目介绍和源码)
随机推荐
还在原地踏步,提高软件测试能力的方法你知道吗?
day5-x
Full arrangement of numbers (digital password dictionary)
After receiving the picture, caigou was very happy and played with PDF. The submission format was flag{xxx}, and the decryption characters should be in lowercase
On absolute value function in C language
数据库常见面试题都给你准备好了
[untitled] task3 multiple recall
Distributed task scheduling
Occupied occupied occupied occupied occupied
Load the source code of 2D 3D virtual anchor in the web page (1: project introduction and source code)
Ceil, floor and round functions
Sword finger offer II 016 Longest substring without repeating characters - sliding window
Semaphore flow control semaphore
Filters and listeners
更改tabledata列名
Jupyter notebook sets the default browser to open with an error syntaxerror: (Unicode error) 'UTF-8' codec can't decode byte 0xd4
Chapter IV - first procedure
软件测试面试官问这些问题的背后意义你知道吗?
Introduction to applet cloud development -- questionnaire evaluation applet practice (7)
Visualization of two-dimensional feature logistic regression prediction results