当前位置:网站首页>Database interview
Database interview
2022-07-28 05:39:00 【jekyhu】
1、 Function of trigger ?
trigger Is a special stored procedure , It is mainly triggered by events . It can strengthen constraints , To maintain data integrity and consistency , You can track operations within the database so that unauthorized updates and changes are not allowed . Can be concatenated . Such as , Triggers on one table contain data operations on another , This operation will cause the table trigger to be triggered .
2、 What is stored procedure ? What to call ?
A stored procedure is a precompile Of 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 . call : 1) You can call a stored procedure with a command object . 2) It can be called by external programs , such as :java Program .
3、 Advantages and disadvantages of stored procedures ?
advantage : 1) Stored procedures are precompiled , High execution efficiency . 2) The stored procedure code is stored directly in the database , Call... Directly through the stored procedure name , Reduce network communication . 3) High safety , The execution of a stored procedure requires a user with certain permissions . 4) Stored procedures can be reused , Can reduce the workload of database developers . shortcoming : Poor portability
4、 The difference between stored procedures and functions
stored procedure
1、 Used to complete specific operations or tasks in the database ( If inserted 、 Delete etc. )
2、 The program header statement uses procedure
3、 There is no need to describe the return type when declaring the program header. You can use in/out/in out The parameters of the three modes
4、 As an independent PL/SQL sentence To execute
5、 Can pass out/in out Returns zero or more values
6、SQL sentence (DML or SELECT) Cannot call stored procedures in
function
1、 For specific data ( If you choose )
2、 The program header statement uses function
3、 The return type should be described when the program header is declared , and PL/SQL The block must contain at least one valid return sentence
4、 have access to in/out/in out The parameters of the three modes
5、 Can't execute... Independently , Must be called as part of the expression
6、 adopt return Statement returns a value , And the change value should be consistent with the declaration part , Or through out The variable brought out by the parameter of type
7、SQL sentence (DML or SELECT) You can call functions in
5、 The function of index ? And its advantages and disadvantages ?
Index is a special query table , Database search can use it to speed up the retrieval of data . It's very similar to the catalogue of books in real life , You don't need to query the whole book to find the data you want . The index can be unique , Creating an index allows you to specify a single column or multiple columns . The disadvantage is that it slows down the speed of data entry , It also increases the size of the database .
6、 What fields are suitable for indexing
only 、 Not empty 、 Frequently queried fields
7、 What are the index types ?
logically :
Single column Single line index
Concatenated Multiline index
Unique unique index
NonUnique Non unique index
Function-based Function index
Domain Domain index Physically :
Partitioned Partition index
NonPartitioned Non partitioned index
B-tree :
Normal Normal type B Trees
Rever Key Inversion type B Trees Bitmap Bitmap index
8、 What is business ? What is a lock ?
Transactions are bound together as a logical unit of work SQL Statement grouping , If any statement operation fails, the whole operation will fail , Later, the operation will roll back to the pre operation state , Or there's a node on it . In order to make sure that or carry out , Or not , You can use transactions . Consider having groups of statements as transactions , It needs to pass ACID test , Atomicity , Uniformity , Isolation and persistence . lock : In so DBMS in , Lock is the key to transaction , Locks guarantee the integrity and concurrency of transactions . Like locks in real life , It can make the owner of some data , Certain data or data structures cannot be used for a certain period of time . Of course, there are levels of locks .
9、 What is view ? What is a cursor ?
View : It's a virtual table , It has the same function as the physical table . The view can be added , Change , check , operation , An attempt is usually a subset of rows or columns that have one or more tables . Changes to the view affect the base table . It makes it easier for us to get data , Compared to multi table query . The cursor : It is to effectively process the result set as a unit . The cursor can be positioned on a specific line in the cell , Retrieve one or more rows... From the current row in the result set . You can modify the current row of the result set . Generally, cursors are not used , But when it comes to processing data item by item , Cursors are very important .
10、 Advantages and disadvantages of views
advantage : 1) Access to database , Because the view can selectively select a part of the database . 2 ) Users can get results from complex queries through simple queries . 3 ) Maintain data independence , Trying to retrieve data from multiple tables . 4 ) Different views can be generated for the same data . shortcoming : performance : When querying the view , You have to convert a query from a view to a query on a base table , If the view is defined by a complex multi table query , that , Then you can't change the data
11、 List several ways to connect tables , What's the difference? ?
Internal connection 、 Self join 、 External connection ( Left 、 Right 、 whole )、 Cross connect Internal connection : Only two element tables that match can be displayed in the result set . External connection : The left outer join : On the left is the driver table , All the data in the driver table are displayed , Mismatches in the matching table will not be displayed . Right connection : On the right is the driver table , All the data in the driver table are displayed , Mismatches in the matching table will not be displayed . Full outer join : All mismatched data in the linked table will be displayed . Cross connect : The Cartesian effect , The result is the product of the number of linked tables .
12、 The difference between primary key and foreign key ?
The primary key is unique in this table 、 Don't be empty , Foreign keys can be repeated and 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 .
13、 Query statements in the database is slow , How to optimize ?
1. Index building 2. Reduce the association between tables 3. Optimize sql, Try to make sql Quickly locate the data , Don't let sql Do a full table query , We should take the index , The data Big watches are at the front 4. Simplify query fields , Useless fields do not , Has control over the return result , Try to return a small amount of data 5. As far as possible with PreparedStatement To query , Do not use Statement
14、 What are the three paradigms of database ?
First normal form : Columns cannot be subdivided Second normal form : Rows can be uniquely distinguished , Primary key constraint Third normal form : The non primary attribute of a table cannot depend on the non primary attribute of other tables Foreign key constraints And the three paradigms are level by level dependent , The second paradigm is based on the first paradigm , The third paradigm builds on the first and second paradigms
15、union and union all What's the difference ?
UNION Duplicate records will be filtered out after table linking , Therefore, after the table is linked, the generated result set will be sorted , Delete duplicate records and return results . In practice, most applications will not produce duplicate records , The most common are process tables and history tables UNION. UNION ALL Just simply merge the two results and return . such , If there are duplicate data in two returned result sets , Then the returned result set will contain duplicate data . In terms of efficiency ,UNION ALL than UNION Much faster , therefore , If you can confirm that the two merged result sets do not contain duplicate data , So use UNION ALL.
16、Varchar2 and varchar What's the difference? ?
Char The length is fixed , and varchar2 The length of is changeable , such as , Store string “abc” about char(20), Indicates that the characters you store will occupy 20 Bytes , contain 17 Empty , And the same varchar2(20) Only occupied 3 Bytes ,20 It's just the maximum , When you store characters less than 20 when , Store in actual length . char The efficiency of is to be varchar2 The high efficiency . at present varchar yes varchar2 A synonym for , Industrial standard varchar Type can store empty strings , however oracle You can't do that , Although it reserves the right to do so later .Oracle I developed a data type myself varchar2, This type is not a standard varchar, He will be in the database varchar Column can store an empty string property to store null value , If you want to have backward compatibility ,oracle It is recommended to use varchar2 instead of varchar
17、Oracle and Mysql The difference between ?
1) Library functions are different . 2)Oracle It's managed with tablespaces ,Mysql No . 3) Show all current tables 、 user 、 Change connected users 、 Show current connected users 、 Different statements for executing external scripts . 4) Paging query time ,mysql use limit oracle use rownum
mysql> SELECT * FROM table LIMIT 5,10; // Retrieve record lines 6-15
// If only one parameter is given , It means to return the maximum number of record lines : mysql> SELECT * FROM table LIMIT 5; // Before retrieval 5 A record line
// To retrieve all record lines from an offset to the end of the recordset , The second parameter can be specified as -1: mysql> SELECT * FROM table LIMIT 95,-1; // Retrieve record lines 96-last.
边栏推荐
- 【单例模式】懒汉模式的线程安全问题
- ByteBuffer.position 抛出异常 IllegalArgumentException
- Export excel, generate multiple sheet pages, and name them
- Openjudge: stone scissors cloth
- VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard
- Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
- Framework step by step easy-to-use process
- 项目中问题合集
- Deep learning medical image model reproduction
- ECCV22 最新54篇论文主图整理
猜你喜欢

Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade

Digital twin solutions inject new momentum into the construction of chemical parks

How to compare long and integer and why to report errors

多系统架构设计思考

科研论文写作方法:在方法部分添加分析和讨论说明自己的贡献和不同

ByteBuffer. Position throws exception illegalargumentexception

JUC notes

IDEA配置 service(Run Dashboard) 服务,多模块同时启动

使用navicat或plsql导出csv格式,超过15位数字后面变成000(E+19)的问题

CentOS7安装MySQL5.7
随机推荐
Framework step by step easy-to-use process
Mutual conversion between latex and word
Personal summary of restful interface use
Mysql数据库索引(innodb引擎)
URL form
[singleton mode] thread safety of lazy mode
正则表达式
深度学习热力图可视化的方式
Methods of gflops and total params of pytorch calculation model
BigDecimal 进行四舍五入 四舍六入和保留两位小数
block yandex bot
BigDecimal rounds and retains two decimal places
SSLError
IO流的使用
Openjudge: matrix multiplication
The essence of dynamic convolution
Long和Integer如何进行比较,为什么报错
Pytorch uses maxpool to realize image expansion and corrosion
Problems encountered when the registry service Eureka switches to nocas
低照度图像数据集