What database, Introduction and classification database

1. Classification Database

Divided into relational databases and non-relational database.

1.1 relational database

Relational database is a database based on the relational model to create a so-called relational model is "one to one, one to many, many to many" and other relational model, relational model refers to the two-dimensional table model, it is a relational database by two data organization and a link between the dimension tables of.
Common relational databases: Oracle, DB2, Microsoft SQL Server , MySQL and so on;

1.1.1 ACID theory

ACID, refers to a database management system (DBMS) in a firm has four properties: Atomicity (Atomicity), consistency (Consistency), isolation (Isolation), persistent (Durability).
In database systems, a transaction is a complete process consists of a series of logical database operations thereof. Such as bank transfer, account deductions from the original, and add money to the destination account, the sum of these two database operations to form a complete logical process, not split. This process is called a transaction, in order to ensure the smooth execution of the transaction, the transaction must have the ACID properties.
Atomic: atomicity means that a transaction is an indivisible unit of work, which operate either do or do not do. That transfer either succeed or fail transfer, is in the middle of the state does not exist.
If you can not guarantee what will happen atomicity? Data inconsistency occurs, A minus the account 50, while the B account an increase of 50 primitive operation failed. The system will be lost for no reason 50.

Isolation: Isolation means that when a plurality of transactions concurrently executing operations within a transaction are other transactions are isolated and can not interfere with one another concurrently executing various transactions. As shown below:
Isolation illustrationPersistence: Persistence means that once the transaction commits, its changes to the database should be permanent. The next operation or other faults should not have any effect on them.

Consistency: Consistency means before and after transaction execution, data in a legal state, this state is (ie, logical data you have written) on semantics. It can be said when the transaction is completed, all data must be consistent state.
Example One: A 200 yuan account, transfer out 300 yuan, account balance -100 A case element. You naturally found at this time the data is inconsistent, and why? Because you define a state, the balance of this column must be greater than zero.

One problem: Mysql how to ensure consistency?

  1. From the database level, the database by atomicity, isolation, durability to ensure consistency. That is among the four ACID properties, C (identity) is the goal, A (atomic), I (isolation), D (persistence) is the means, in order to ensure the consistency of the means, provided by the database. AID database must implement three major characteristics, be possible to achieve consistency. For example, can not guarantee atomicity, consistency obviously can not be guaranteed.

  2. Affairs can not exist in the code constraint violations, once there is consistency still not guaranteed. For example, in the example you transfer in, your code is not intentionally added to the B-account money, it still can not guarantee consistency. Accordingly, the application layer must also be from the viewpoint of whether the database data is valid is determined by the code, and then decide to roll back or to submit data!

Guess you like

Origin blog.csdn.net/u014370122/article/details/95197753