Database of some important concepts and summarize data types (study notes) - python

  1. Database some concepts:
    1.1.PRIMARY primary key KEY
    What is the primary key: unique key consisting of a table or a plurality of rows, that is, through the one or more columns that uniquely identify a record of (normal is achieved by a).
    Features: a primary key can not contain a null value Null 2. Primary often set to an integer, long integer, 3 and increment the AUTO_INCREMENT...
    The table may not have primary keys, but in general the table design, there will be a primary key.
    1.2 index index
    role index: can be seen as a large dictionary catalog, in order to quickly retrieve used. Space for time, significantly improve query performance.
    Side effects: delete, modify, add efficiency reduction
    can be set to an index or multiple columns.
    Index Classification:
    primary key index: primary key will automatically create a primary key index, primary key itself is to quickly locate the only record.
    The composition of the index table of the index must be unique, but can be empty (NONE), a non-null value must be unique: unique index on
    the general index: no uniqueness requirement is to build a dictionary directory only.
    1.3 Constraint (constraint)
    UNIQUE constraint (constraint unique key)
    defines a unique key index, to define a unique key constraints
    PRIMARY KEY constraint
    defines the primary key, the primary key constraint definition.
    Foreign key constraint Foreign Key:
    . Foreign key, listed in Table B, the primary key is associated in Table A, Table B the column is a foreign key
    1. If you insert a data in Table B, the foreign key B of the column is inserted a value, which must be present in the primary key of table a, table B modified foreign key value is the same, the same foreign key values in table a to be present.
    2. If Table A To delete a record, it will delete a primary key, so if the table B is referenced to the primary key, you must delete the table B is referenced to record the primary key before you can delete table records A, otherwise failed to delete.
    3. Modify the primary key of Table A, since the uniqueness of the primary key, the modified primary key corresponds insert new primary key, then the table B cited in this master key, prevents the primary key modification of Table A, must delete the associated records of Table B, a can modify the primary key table.
    Foreign key constraints, in order to ensure data integrity, consistency, eliminate data redundancy, data corruption.
    Easy to use multiple foreign key constraints.

1.4 View
View: also called virtual table, looks like a table. It is generated by the query statement. CRUD operations may be performed by a view.
The role of view:

  1. Streamline operations, complex query SQL statement is defined as a view, you can simplify the query.
  2. Data security: View to show only some of the columns of the real table, or the result of calculation, to hide the real table.
    (CRUD can view, query suggestions with a view, you can use tools to complete view)

2. Data Type:
data type in MYSQL:
Type:

  1. Tinyint 1 byte, the range of -128 to 127 signed, unsigned range is 0 to 255. bool or boollean, is tinyint, 0 for false and non-zero real
  2. Smaillint 2-byte, unsigned range is -32768 to 32767. The unsigned range is 0 to 65535
  3. Int Integer 4 bytes, the same integer, unsigned range -2147483648 to 2147483647. unsigned range is 0 to 4,294,967,295 (maximum 10 ID)
  4. Bigint Long, 8 bytes, the range is -9223372036854775808 signed to unsigned range 9223372036854775807 0-18446744073709551615 (20)
  5. Float single-precision floating decimal precision to about 7
  6. Double Double precision floating point is accurate to approximately 15 decimal
  7. DATE date, to support a range 1000-01-01 to 9999-12-31
  8. DATETIME supported range 1000-01-01 00:00:00 to 9999-12-21 23:59:59
  9. TIMESTAMP timestamp range 1970-01-01 00:00:00 2037
  10. Char (M) of fixed length, padded with spaces to the right has reached the required length. M is the length, in the range of the number of characters refers 0-255.M. (Not long enough to fill the space)
  11. Varchar (M) variable-length string. M represents the maximum length of the column. M range is 0 to 65535. 65535, but do not break through the maximum number of bytes
  12. Text Large text. 65535 the maximum length (2 ^ 16-1)
  13. BLOB big bytes. The maximum length is 65535 (2 ^ 16-1) bytes BLOB column

    LENGTH function returns the number of bytes, while char and varchar M is the number of characters defined limit.
    Char may be turned into a string of equal length, space for time, slightly higher efficiency; VARCHAR longer, saving space.

Guess you like

Origin blog.51cto.com/14477933/2425786