[Database] part interview preparation

Database section

Caused his interview preparation questions, add your own and integrate other people sharing!

1. The role of the trigger?

A trigger is a special stored procedures, mainly triggered by events to be executed. It can strengthen the constraints, to maintain the integrity and consistency of the data, you can track actions within the database in order to not allow unauthorized updates and changes. You can cascade operation. For example, the table contains data on the operation of the other trigger on a table, which in turn causes the operating table the trigger is triggered.

2. What is a stored procedure?

A stored procedure is a precompiled SQL statement, the advantage of allowing a modular design that is created once, later in the program can call multiple times. If you need to do many times a particular SQL, stored procedures using simple SQL statement is executed faster than that.

3. How to call a stored procedure?

1, you can use a command object to call a stored procedure.
2, can be used for calling external programs, such as: java program.

4. The advantages and disadvantages of stored procedures ?

Advantages:
1, stored procedures are precompiled, high efficiency.
2, stored procedure code stored directly in the database, called directly by the stored procedure name, reduce network traffic.
3, safe, execute the stored procedure requires the user to have certain privileges.
4, stored procedures can be reused, can reduce the workload of database developers.

Disadvantages:
poor portability

5. What is the index?

The index is the structure of the database table value a plurality of columns or sorting.

6. The index of the advantages and disadvantages?

Advantages:
1, greatly accelerate the speed of data retrieval;
2, create unique index, ensure the uniqueness of each row of database table data;
3, accelerating the connection between the table and the table;
4, using grouping and sorting clause data retrieval, can significantly reduce the query time grouping and sorting.

Disadvantages:
1, slows the speed of data entry, but also increases the size of the database.
2, index requires additional physical storage space than the data in Table
3, to create and maintain an index index takes a certain time
4, when the table update operation, the index needs to be rebuilt, which reduces the speed of data maintenance.

7. What kind of fields for indexing

The only, not empty field frequently requested

8. What types of index?

Logically:
Single column single row index
Concatenated multiple row index
Unique unique index
NonUnique non-unique indexes
Function-based functional index
Domain domain index

Physically:
Partitioned partitioned index
NonPartitioned non-partitioned index

Tree-B:
Normal Normal Form B tree
Rever Key Tree inversion type B
Bitmap bitmap index

9. What cursors are?

Cursor: as a means to effectively process the query result set out. The cursor can be set in a particular cell line, the current line retrieve one or more rows from the result set. You can make changes to the current row result set. Generally do not use a cursor, but need to process the data one by one when the cursor is very important.

10. What is a view?

View: is a virtual table, it has the same functionality as a physical table. Can be increased to view, change, operation, there is usually attempted to a table or a subset of the plurality of rows or columns of the table. Changes to the view will affect the base table. It allows us to obtain data more easily, compared to multi-table queries

11. The view of the advantages and disadvantages

Advantages:
1, access to the database, because the view may be selectively selected part of the database. 2, the user can obtain the query result from the complex by a simple query.
3, to maintain the independence of the data, trying to retrieve data from multiple tables available.
4, can produce different views of the same data.

Disadvantages:
When a query view, the view must be converted to a query paired basic query table, if this view is defined by a complex multi-table queries, you can not change the data.

12. The table lists several connections, what's the difference?

The connection from the connector, the external connector (left, right, full), the cross-connection: only two elements matching appearances concentrated in the result. An outer connector: left outer join: left driven table, the table show all the data driver, does not match the match table is displayed. Right external connection: the right to drive the table, the table show all the data driver, does not match the match table is displayed. Full outer join: All data in the table does not match the connection is displayed. Cross-connect: Cartesian effect, the result is the product shows a link table.

13. The difference between primary keys and foreign keys?

A primary key is unique in this table, the only non-empty, the only foreign key blank may be repeated; primary key and foreign key to another table, the foreign key can not create the mapping table does not exist.

14. The query is slow in the database, how to optimize?

1, construction of the index
2, to reduce the association between Table
3, optimization sql, sql soon as possible so that positioning data, do not let the sql query to do the whole table, should take the index, the large amount of data table top surface
4, a simplified inquiry field, useless fields do not have to return the results of control, try to return a small amount of data
5, try to use PreparedStatement query, do not use Statement

15. Three Forms database

Paradigm 1: ensure atomicity of each column
2 Model: Table 1 describes only a matter
of Paradigm 3: the outer key table associated made

The difference 16.Oracle and Mysql?

1, various library functions.
2, Oracle table space is managed, Mysql not.
3, shows the current all the tables, users, change user connections, different display currently connected users, perform the statement of the external script.
4, when the time paging query, mysql by using limit oracle rownum

17. What is PL / SQL?

PL / SQL is a programming language called procedural language SQL (Procedural Language / SQL). PL / SQL is Oracle database extensions to SQL statements. In the use of common SQL statement adds the characteristics of the programming language, the PL / SQL the data manipulation and query tissue procedural unit PL / SQL code, to implement complicated functions through logic, circulation operations or calculations. PL / SQL Oracle database has only. MySQL does not currently support of PL / SQL.

18.truncate and delete difference

TRUNCATE TABLE and DELETE statement with no WHERE clause is functionally the same: both remove all rows in the table. But TRUNCATE TABLE is faster than DELETE speed, and fewer system and transaction log resources used.
DELETE statement deletes each row, and each row is a record deleted in the transaction log.
TRUNCATE TABLE to delete data stored by the release of the data page table data used, and only release page recorded in the transaction log.

TRUNCATE, DELETE, DROP put them together:
TRUNCATE TABLE: delete content, free up space without deleting the definition.
DELETE TABLE: delete content without deleting the definition, not free up space.
DROP TABLE: Delete content and definition, free up space.

19.oracle time acquisition system

select to_char(sysdate, 'yyyy-MM-dd HH24:mi:ss') from dual;

20.oracle how to remove heavy

The use of distinct keywords

Guess you like

Origin blog.csdn.net/weixin_43266090/article/details/90720144