Home » MySQL » MySQL the operation data in table two

MySQL the operation data in table two

this article is a follow-up part of the creation and operation of the MySQL data sheet.

when you create a table, and to the INSERT data, and not all fields each line will add a record, so this time there may be some value of null value, we can through some operations to control certain fields can null ! Of course have some value to the ID number that is only, we also need some operations to control the uniqueness of their


empty and non empty (both can choose one)

Whether the NULL and NOT NULL definitions are nonempty is determined when the table is created.

, for example:


->username, VARCHAR (20), NOT, NULL,

->age TINYINT NULL (or does not write, defaults to null)

In the above - >); create the rules under the background of

INSERT, TB2, VALUES (NULL, 20); illegal, error,

INSERT, TB2, VALUESI (` PITBULL ', 20); legal!

The uniqueness of the

data and the uniqueness of the data depend mainly on some keys (KEY) to implement the

PRIMARY KEY (primary key)

 primary key is equivalent to a field, such as an attribute of username. When username has this property, the entire table cannot have duplicate names
The nature of primary keys:
Each data table has only one primary key
The primary key guarantees the uniqueness of the record
The primary key is automatically NOT NULL (that is, data that has the primary key property cannot be empty)

development: AUTO_INCREMENT is automatically numbered and must be used in combination with primary keys. By default, the initial value is 1, with an increment of 1
each time
The data types that can be used with AUTO_INCREMENT can be integers or floating points. If there is a floating point number, the number of decimal places must be 0, that is, FLOAT (8,0), FLOAT (6,0);

The AUTO_INCREMENT must be used with the primary key, but the primary key does not necessarily have to be used with the.


, for example:



->name VARCHAR (20)

- >


UNIQUE KEY unique constraint

  • unique constraints guarantee the uniqueness of records

    The unique constraint field can be a null value (NULL) (you can have multiple null values, NULL, non null, non repeatable),

    Each data table may have multiple unique constraints,

    For example:

    ->CREATE TABLE tb4 (


    ->name VARCHAR (20)

    - >
  • );

adds another key:



When the record is inserted, the default value.

is assigned automatically if the assignment is not explicitly assigned to the field

, for example:


->id, TINYINT,


- >