Face questions were recorded: articles database

1, the three major paradigms database

Database design of the three paradigms

In order to establish redundancy smaller, well-structured database, you must follow certain rules when designing the database. In a relational database such rules is called paradigm.

Paradigm is summed up in line with a certain kind of design requirements, in order to design a well-structured relational database, you must meet certain paradigm.

Three paradigms:

The first paradigm: Let R when all the attributes are not decomposed at a more basic data unit, said R satisfies the first paradigm is abbreviated as 1NF. The first paradigm is to meet the minimum requirements for the standardization of relational schema. Otherwise, there will be a lot of basic operations can not be implemented in a relational schema;

The second paradigm: If the first normal form relational schema R and R have all non-primary attributes are totally dependent on the properties of each of the candidate key of R, R, said second normal, abbreviated 2NF;

Third Pattern: Let R be a relational model of the first condition is satisfied Paradigm, R X is an arbitrary set of properties, if X is dependent on non-transmission of one candidate keyword any R, R satisfies said third paradigm, referred to simply as 3NF .

understanding:

First Normal Form

1, each column attributes are attribute values ​​can not be divided, ensuring atomicity of each column

2, two of the same or similar properties, or similar, as far as possible the same properties combined column, to ensure that no redundant data is generated.

Second Normal Form

1, each row of data can only be associated with one of the columns that line of data only one thing. Repeated as long as the data in the data column, the table it should be split open.

2, a person booked several rooms at the same time, an order number will come out pieces of data, like this contact is repeated, it will cause data redundancy. We should be open to him.

Third Normal Form

1, data can not transfer relationship exists, i.e., each related to the primary key attribute is directly related rather than an indirect relationship. Like: a-> b-> c containing such a relationship between the attribute is inconsistent with the third paradigm.

For example, Student Form (student number, name, age, gender, where schools, colleges and universities address, telephone colleges and universities)

Such a table structure, there is the above relationship. Student ID -> your institution -> (Address of institution, colleges telephone)

This table structure, we should be open, as follows.

(Student ID, name, age, gender, where institutions) - (where schools, colleges and universities address, telephone colleges and universities)




2, MySql stored procedure

What is a stored procedure:

Stored procedures are programmable functions , created and saved in the database can be used by the SQL statements and control structures. When you want to perform the same function in different applications or internet, or a package with a particular function, the storage process is very useful. Database stored procedure can be seen as an object-oriented programming in the simulation process, which allows controlled access to data. A stored procedure is an important feature of the database, MySQL does not support stored procedures prior to 5.0 , which makes MySQL discount on the application. Fortunately, start MySQL 5.0 support for stored procedures, so that can greatly improve the processing speed of the database, but also can improve the flexibility of database programming.




3, MySql engine (the difference between the innoDB and MyISAM)

InnoDB:
support for transaction processing
unlocked reading
support foreign key
support line lock
FULLTEXT index type is not supported
not save the table specific number of rows, scanning table to calculate how many rows
during DELETE table, line by line is deleted
InnoDB data and an index table stored in the space inside the
cross-platform can be copied directly used
in InnoDB AUTO_INCREMENT type field must contain the index of
the table is difficult to compress

MyISAM:
does not support transactions, the rollback will result in incomplete rollback, it does not have the atomicity
does not support foreign keys
do not support foreign key
support full-text search for
a specific number of lines to save the table, without a time where, the number of rows returned directly saved
DELETE table when the first drop table, and then rebuild the table
MyISAM table is stored in three files. frm file storage table definition. Data files are MYD (MYData). Index file is MYI (MYIndex) extension of
cross-platform difficult to directly copy
MyISAM AUTO_INCREMENT type field can make the establishment of joint index
table can be compressed

Select:
Because MyISAM relatively simple so the efficiency is better than InnoDB if the system read more, write less. Low atomic requirements. So MyISAM best choice. MyISAM and fast recovery speed. Backup can be used to cover the direct recovery.
If the system is reading less, write more time, especially when high concurrent writes. InnoDB is the first choice.




4, MySql Database Performance Optimization

Database performance, I personally think that the most important is the storage engine of choice.

This is not particularly a line, give us a big God of blog links, database performance optimization Comments: ----> https://www.cnblogs.com/luxiaoxun/p/4694144.html




5, SQL optimization

1. query optimization, to try to avoid full table scans, you should first consider indexing by the column involved in where and order.

2. Should be avoided fields null value judgment in the where clause, it will cause the engine to give up using the index and full table scan.

3 should be avoided in the where clause! = Or <> operator, otherwise the engine to give up using the index and a full table scan.

4. The connection conditions shall be avoided or used in the where clause, if there is a field index, a field is not indexed, will cause the engine to give up using the index and a full table scan.

5.in should be used with caution and not in, otherwise it will lead to a full table scan

6. Use like fuzzy search can lead to full table scan, usually a word search engine framework used to implement fuzzy search

7. Try to avoid an asterisk, using field names instead

8. instead make use union all union

9. make use of <=,> = instead beetween and




Reference article:
Database Performance Optimization: https: //www.cnblogs.com/luxiaoxun/p/4694144.html
three paradigms: https: //www.cnblogs.com/1906859953Lucas/p/8299959.html




Guess you like

Origin www.cnblogs.com/blackjoyful/p/11547005.html