MySql 17 questions pavement

1. MySql face questions of 17

1.1 Role of the flip-flop?

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.

1.2 What is a stored procedure? To call what?

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. Call: 1) You can call a stored procedure with a command object. 2) can be used for calling external programs, such as: java program.

1.3 advantages and disadvantages of stored procedures?

Advantages: 1) is a stored procedure precompiled high efficiency. 2) stored procedure code is stored directly in the database, called directly by the stored procedure name, reduce network traffic. 3) safe, execute a stored procedure requires the user to have certain privileges. 4) stored procedure can be reused, reducing the workload of the database developer. Disadvantages: poor portability

1.4 difference stored procedures and functions

1.4.1 Stored Procedures

  1. For performing a specific operation or task in the database (e.g., insert, delete, etc.)
  2. Disclaimer procedure program head
  3. Need not be described return type may be used in / out / in parameter out of three modes when the program statement head
  4. Can be performed as a stand-alone PL / SQL statements
  5. Can / in out returns zero or more values ​​out
  6. SQL statement (DML or SELECT) call a stored procedure is not available

1.4.2 Functions

  1. For a particular data (e.g., selection)
  2. Statement by the head of the program function
  3. Return Type Description To program statement head, and PL / SQL block should include at least one valid return statement
  4. It can be used in / out / in out three modes of parameters
  5. Can not be performed independently, it must be invoked as part of an expression
  6. A return statement return values, and change the value to be consistent with the declaration section, may be the type of parameter bands through out the variable
  7. SQL statement (DML or SELECT) can call the function

1.5 Role of the index? What are its advantages and disadvantages?

Index on a special lookup table, search the database can use it to speed up retrieval of data. It is very similar to the real-life book catalog, you do not need to query the contents of an entire book to find the data you want. Index may be unique, allowing to create an index to specify a single column or a plurality of columns. The disadvantage is that it slows the speed of data entry, but also increases the size of the database.

1.6 What kind of fields for indexing

The only, not empty field frequently requested

Index 1.7 What types?

logically:

  • Single column single row index
  • Concatenated multi-line index
  • Unique unique index
  • NonUnique non-unique index
  • Function-based index function
  • Domain physically domain index:
  • Partitioned Partitioned Indexes
  • NonPartitioned non-partitioned index
  • B-tree :
  • Normal Normal B-tree type
  • Rever Key inversion type B Bitmap bitmap index tree

1.8 What is a transaction? What is the lock?

Transaction is to be bound together as a logical unit of work packets SQL statement, a statement, if any operation fails then the whole operation was a failure, after the operation will be rolled back to the state before the operation, or has the nodes. In order to ensure either executed or not executed, you can use the transaction. To have a group of statements considered as a transaction, we need to pass the ACID test, namely atomicity, consistency, isolation and durability. Lock: So in the DBMS, the lock is the key to the transaction, the lock can ensure the integrity and transaction concurrency. As in real life in the lock, which allows owners of certain data, can not use certain data or data structures within a certain period of time. Of course, the lock also points level.

1.9 What is a view? What cursors are?

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. 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.

View of the advantages and disadvantages of 1.10

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) maintain the independence of the data, trying to retrieve data from multiple tables available. 4) can produce different views of the same data. Disadvantages: Performance: When a query view, you must convert the query query paired base table view, if the view is defined by a complex multi-table queries, then you will not be able to change data

Table 1.11 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.

1.12 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.

1.13 query speed is very slow in the database, how to optimize?

  1. Construction index
  2. Reducing correlation between the tables
  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. Simplify the query 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

1.14 What database three paradigms?

  • The first paradigm: the column can not be divided
  • The second paradigm: row may uniquely identify the primary key constraint
  • Third Pattern: non-primary key attribute table can not rely on external constraints and other non-primary property sheet and a three-dependent paradigm is a second paradigm paradigm based on the first, third paradigm establishing a first section the two paradigms

1.15 union and union all what is the difference?

UNION making table will filter out duplicate links records, so the result set in the table will link the resulting sort operation to remove duplicate records and then returns the result. Most practical applications are no duplicate records, the most common is the process table and the history table UNION. UNION ALL simply returns the results after the merger of the two. Thus, if the result set returned by two duplicate data, then returns the result set will contain duplicate the data. From the efficiency, UNION ALL UNION faster than a lot, so if you can confirm that the merger of two results set does not contain duplicate the data, then use UNION ALL.

1.16 Varchar2 and varchar What is the difference?

Char length is fixed, and the length can vary varchar2, for example, store the string "abc" to char (20), representing the character stored in your account for 20 bytes, it contains 17 empty, and the same VARCHAR2 (20) only three bytes, but the maximum value of 20, when the character you stored is less than 20, the actual length of the memory. char varchar2 efficiency to be high efficiency. Currently varchar varchar2 is synonymous with the industry-standard varchar type can store an empty string, but the oracle can not do this, although it reserved the right to later do so. Oracle's own developed a data type varchar2, this is not a standard type of varchar, varchar column he will be replaced by an empty string characteristics stored null value is stored in the database, if you want to have backwards compatibility, oracle recommended varchar2 rather than varchar

1.17 of the difference between Oracle and Mysql?

  1. Different library functions.
  2. Oracle table space is managed, Mysql not.
  3. Displays the current all the tables, users, change user connections, display statement currently connected users, perform an external script different
  4. When paging query time, mysql by using limit oracle rownum
mysql> SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15 
//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1: mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last. 
//如果只给定一个参数,它表示返回最大的记录行数目: mysql> SELECT * FROM table LIMIT 5; //检索前 5 个记录行 
//换句话说,LIMIT n 等价于 LIMIT 0,n。 5)sql的语法的不同。

Guess you like

Origin www.cnblogs.com/trent-fzq/p/11241619.html