SQL tables connections What?

SQL into the connector set according to the result: the connector, the external connector, the connection cross-
connections within: Inner combination join on, two tables are met. En divided into equivalent connections, ranging connections, natural connection.
Equijoins: the same two columns in the table will appear in the result set.
Natural connection: the two tables in the same specific list will be merged into the same column listed in the result set.
External connection: divided into left (outer) connector, a right (outer) connector, all connected to
the left (outer) connector: A left (outer) join B , A in the table is based on all the data of Table A, B TABLES composition not for.
Right (outer) connected: A right (outer) join B , in Table B, based on all the data table B, A combination of some tables, no bit null.
Fully connected: A full (outer) join the same combination of two tables together, A table has, B table no data (shown as null), have the same table B, A is not displayed table is null.
Cross-connect: cross join, it is the Cartesian product.
2, three paradigms
1NF: table fields are a single property, not separable.
2NF: 1NF on the basis of the table all of the non-primary attributes have to be totally dependent on any set of candidate key, is not only dependent on a key attribute of the candidate.
3NF: 2NF on the basis of the table all of the properties are not dependent on other non-primary property.
Simply means: 1NF represent each attribute indivisible, 2NF represents non-primary property does not exist in part dependent on the primary key, 3NF represents non-primary key attributes of the primary transfer dependence absent.
3, operating tables
to create tables: create table table name (column name constraint type 1, type 2 column constraints ...)
to delete tables: drop table table name
Change (update changes the structure, not recorded) table: alter table table add | drop column name | approximately
bundle name
is inserted record: insert into table ... values ...
Update Record: update table set column name = value where conditions
delete record: delete from table where conditions
4, data integrity,
data integrity refers to the consistency and accuracy of the data stored in the database.
Integrity categories:
(1) physical integrity: primary key value must be unique and non-empty. (Primary key)
(2) referential integrity (also called referential integrity): foreign key is either empty, or the main reference table records exist. (Foreign key constraints).
(3) user-defined integrity: the constraints for a particular relational database.
5, SQL query optimization
(1) is connected from the perspective of optimization table: to make use of the connection because the connection is a combination of two rows of the table are met, wherein the outer connector is a reference table of all.
(2) Try to use stored procedures instead of the temporary write SQL statements: because the stored procedure is a collection of pre-compiled SQL statements, which can reduce compilation time.
(3) from the perspective of the optimization index: those commonly used query fields CV index, query time when such an index scan, block data are not read.
(4) There are some common select optimization techniques:
(5) A, only those who need access to the query field, instead of the * select
B, will filter more records where to forward the statement: In a SQL statement, if a condition where the filter more database records, more accurate positioning, where the conditions to be more forward.

6, the role of the index, the difference between the index and aggregate non-clustered index

The index is a database object, use the index, a database program may be no need to scan the entire data, you can find where the target data to improve search efficiency. Underlying index B-tree is employed.

Clustered index: The key and then recorded in the table to sort the data lines.
Non-clustered index: recording independent structure, so the key contained non-aggregated, and each key entry has a pointer to the data lines simply.

Clustered index and non-clustered index differences:
(1) physical storage aggregated sorting index by index, so the non-aggregated physical storage are not sorted index.
(2) clustered index insert, update data faster than non-clustered indexes slow, single query faster.
(3) held clustered index the leaf node is the time of data items, but not yet the aggregation node is a leaf node pointer to the data item.
(4) a table can have only one clustered index (because there is only one sort), but can have multiple non-clustered indexes.

7, the difference between the stored procedures and functions

(1) function returns a value, the return value is not stored procedure.
(2) Since there is no return value stored procedure, it is not the execution result of the assignment to variables stored procedure; function returning type, the function is called, the execution result of the function may be assigned to the variable. In other words, the function can be used in select statements, and stored procedures can not.

Guess you like

Origin www.cnblogs.com/huaihe/p/11324464.html