SQL, Paradigm, transaction

Source: Internet
Author: User

Database paradigm:

The construction database must follow certain rules. In a relational database, this rule is the paradigm.

A paradigm is a collection of relational patterns that conform to a certain level. The relationships in the database must meet certain requirements, that is, to satisfy different paradigms.

The paradigm that satisfies the minimum requirements is the first paradigm. On the basis of the first paradigm, further satisfying more requirements is called the second paradigm, and the rest of the paradigms are based on the second analogy. In general, the database simply satisfies the third paradigm.

First normal form (1NF):

In any relational database, the first paradigm (1NF) is the basic requirement for relational schemas, and a database that does not meet the first normal form (1NF) is not a relational database.
The so-called First paradigm (1NF) refers to the fact that each column of a database table is an indivisible basic data item and cannot have multiple values in the same column, that is, an attribute in an entity cannot have multiple values or cannot have duplicate properties.

-----First paradigm is a column with no duplicates.

Second Normal form (2NF):

The second paradigm is established on the basis of the first paradigm, that is, satisfying the second paradigm must first satisfy the first paradigm. The second paradigm requires that each instance or row in a database table must be divided by a unique region.

It is often necessary to add a column to the table to store the unique identity of each instance.

-----Second paradigm is that a non-principal attribute is dependent on the primary key.

Third paradigm (3NF):

Satisfying the third paradigm must first satisfy the second paradigm. In short, the third paradigm requires that a database table not contain non-primary key information already contained in other tables.

----The third paradigm is that properties do not depend on other non-primary properties.

Database transactions:

A database transaction is a series of operations performed as a single logical unit of work (Transaction).

Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully.

Example:

Imagine a transaction of online shopping where the payment process includes at least the following steps of database operations:

Update the inventory information of the products purchased by customers

Save customer payment information-may include interactions with the banking system

Generate orders and save to database · Update user-related information, such as the number of purchases, etc. normally, these operations will proceed smoothly, the final transaction is successful, and all the database information related to the transaction has been successfully updated. However, if there is a mistake in any part of the process, such as an exception when updating commodity inventory information, the customer's bank account is under-deposited, and so on, will cause the transaction to fail. Once the transaction fails, all the information in the database must remain unchanged before the transaction, such as failure to update the user information in the last step, resulting in the failure of the transaction, then it must be ensured that the failed transaction does not affect the state of the database-the inventory information has not been updated, the user has not paid, and the order has not been generated. Otherwise, the database information will be chaotic and unpredictable.

Database transactions are the technology used to ensure the smoothness and predictability of transactions in this situation.

Begin Tran (or transaction)--Start transaction

Commit--Commit Transaction

Rollback--ROLLBACK TRANSACTION

Transaction characteristics:

A atomicity (atomicity)

C Conformance (consistency)

I isolation (isolation)

D Persistence (Durability)

@ @ERROR is a condition that determines whether a transaction is wrong, the error-free value is 0, and the error value is not 0.

To create a transaction and use:

SQL, Paradigm, transaction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.