Java Learning Handbook: Principles of Database

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/MaybeForever/article/details/88787034

First, the function of the SQL language what?

Is an abbreviation SQL Structured Query Language, which functions include data query, data manipulation, data definition and data control four parts.

1, data querySELECT (select matching records)
2, data manipulation (the DML) INSERT (insert a record), Update (update statement), Delete (delete records), SELECT (select records)
3, data definition ( DDL) the Create (set up a data table), drop (delete data table), the ALTER (change data table)
4, data control (DCL) grant (grant system privileges to users), REVOKE (recovery of system privileges)

Second, the difference between the inner and the outer connector of the connector

En , has become a natural connection, only two lines to match the appearances of focus appear in the results. Returns a result set selected two tables all the data match, discard the data does not match. Because the connector is to delete all the rows in the table with no other connection to match the results from the table, so the connector may result in loss of information. (The connection is to ensure that all the rows in two tables satisfy the join condition)

External connection , only the external connection lines that meet the connection conditions, but also includes the coordinates (left outer connector), all the data lines right table (right outer connection) or two sides link table (full outer join) was added.

Show only records that meet the connection conditions of the connector, in addition to connecting external display records that meet the join condition, but also displays the records in the table.

Third, what is a transaction?

A transaction is a database in a single execution unit (Unit), which usually consists of high-level database manipulation language (such as SQL) or programming language (such as C ++, Java, etc.) caused by the implementation of user-written program.

Transaction must satisfy four properties, i.e. atomicity (Atomicity), consistency (Consistency), isolation (Isolation), persistent (Durability), i.e. ACID4 kinds of attributes.

(1) atom of :All the operation of the entire transaction, either completed or not completed all impossible stuck in the middle of a link. Transaction error occurs during execution, it will be rolled back (Rollback) to the state before the start of the transaction, as the transaction never performed the same.

(2) Consistency :After a transaction prior to execution and implementation, database data must remain consistent state

(3) isolation : if there are two or more transactions to execute concurrently, in order to ensure data security,The operations of the internal affairs of a transaction isolation, will not be seen by other transactions in progress

(4) Endurance :After the transaction is completed, the transaction changes made to the database will be permanently stored in the database, and will not be rolled back. When a system or media failure, the modifications are permanently maintained.

Under normal circumstances, to terminate the transaction by COMMIT or ROLLBACK statement, when the COMMIT statement is executed, all changes made since the transaction start made to the database to become permanent, and are written to disk; and when the ROLLBACK statement is executed all transactions since the start of the changes made to the database will be revoked, and the contents of the database is returned to the state it was in before the transaction began.

Fourth, the difference between the different paradigms

There are common paradigm: 1NF, 2NF, 3NF, BCNF and 4NF .

(. 1) 1NF (First Pattern) :Normalization is the first column of each database table data items are substantially inseparable, The same column can not have more than one value, i.e., an entity attribute values ​​can not have or can not have multiple duplicate attribute. Paradigm model requires a first attribute value can no longer be split into smaller portions, i.e., not a property item or combination of attributes from the group attributes. In short, the first paradigm is no duplicate column.

(2) 2NF (second normal form) : The second paradigm is built on the basis of the first paradigm, that meet the second paradigm must be met first normal form.The second paradigm requires that each instance of a database table or row must be unique distinguishing

(. 3) 3NF (Third Pattern) : If R is a second relational schema paradigm,And each non-primary property does not depend on the transfer candidate key R, R is called the third paradigm model.

(. 4) the BCNF : It is built on the basis of the third paradigm, if R is the first paradigm relational schema,And each R depends on the transmission properties are not a candidate keyThen said R is BCNF mode.

(. 5) 4NF (Model IV) : Let R be a relation model, D is multi-value dependent on the set R. If the D value is dependent on the presence of the multi X → Y, X must be a super-R bond, then R is said fourth normal mode.

Fives,What is the trigger?

Triggers are a special type of stored procedure that is triggered by an event, rather than a program manual or call the start, when the database has special operations that are triggered by events in the database, automate these SQL statements. Use trigger can be used to ensure the validity and integrity of the data, perform more complex than the constraint data constraints.

Depending on the SQL statement, the trigger can be divided into DML triggers and DLL trigger . DML trigger is a stored procedure performed when data manipulation language database server event occurs, there is After two and Instead Of triggers. After the trigger is activated to trigger one kind of trigger is changed after recording. Instead Of trigger before the record is changed to perform the operation as defined in the trigger itself, rather than executing SQL statement in the original operation. DLL trigger a stored procedure is executed in response to data definition language events.

Trigger is divided into pre-trigger and post-trigger , pre-trigger occurs before the incident, a number of conditions for validating or some preparatory work; after the trigger occurs after the incident, do the finishing work. Before you can get pre-trigger and a new field values, and post-trigger can ensure the integrity of transactions.

Sixth, what is the cursor (Cursor)?

Cursor (Cursor) is a method for processing data, in order to see or deal with the result set of data, providing the ability to focus the cursor one row or multiple rows in the result forward or backward browsing data. It can be used as a pointer to the cursor, which can specify any position in the result, and then allow the user to specify the location of data for processing.

Cursor has the following two advantages:
(1) in the table using the cursor, the rows provide delete and update functions.
(2) facing the cursor, and a set of row-oriented database management system is connected up programming.

Seven, if the database log full, what happens?

Log files (Log File) record all changes to the database data, mainly to protect the database in case of failure, and the use of data recovery. Its characteristics are as follows:
(1) each comprising at least two log database file group. Each log file group containing at least two log file members.
(2) read and write the log file group in a cyclic manner.
(3) Each member of a log file corresponding to a physical file.

For logging database transaction log file can maximize data to ensure consistency and safety, butOnce the database log is full, it can only execute a query such as read, you can not make changes, backup and other operationsBecause any write operations must log, so basically in a state database can not be used.

Eight, union and union all What is the difference?

union carrying tables for computing the set will be removed and repeating elements, the result set will have generated sort operation, remove duplicate records and then returns the result.

union all simply combining the results after two return results. Therefore, if the return result set to two duplicate data, then returns the result set will contain duplicate data.

When performing a query operation, union all much faster than the union.

Nine, what is the view?

Logical window view is selected out of the data base tables in the database component, different from the basic table, which is a virtual table. In the database, storing only the view definition, rather than storing the data items contained in the view, these items are still stored in the original basic table structure. By introducing the view mechanism, the user can concentrate on the data of interest to them (but not all data), thus greatly improving the efficiency and user satisfaction of users. Custom views can be complicated operation and a search condition is connected between the table and the table is not visible to the user, the user simply to view a query can, therefore,View to increase the security of data, but can not improve the efficiency of query

View of the role of the following main points:
(1) to simplify data query.
(2) allows the user to view the same data from multiple angles.
(3) improve data security.
(4) provides a degree of logic independence.

Ten, the database isolation level

  • The Serializable (serialization): can prevent dirty reads, non-repeatable read, phantom read occurs.
  • Reoearable read (Repeatable Read): can prevent dirty reads, unrepeatable reads occurring.
  • Read committed (Read Committed): can avoid dirty reads to occur.
  • Read uncommitted (read uncommitted): the lowest level, in any case can not be guaranteed.

(1) dirty reads : In a transaction processing means in data read uncommitted transaction in another.
(2) non-repeatable read : refers to a database of data, multiple queries within a transaction scope has returned to a different data values. (Since the query interval, is modified by another transaction and submitted a)
(3) Dummy read (phantom read) : Magic Reading is a phenomenon that occurs when a transaction non-independent execution. Phantom reads and non-repeatable read are read another transaction has been submitted, except that: non-repeatable read queries to the same data item, and the magic of reading for a group of data as a whole.

Guess you like

Origin blog.csdn.net/MaybeForever/article/details/88787034