DML operation data in the table

CRUD DML is the recording operation of the table

First, add data

     Syntax:

insert into table [Field Name] values ​​[field value]

        Table Name: Indicates add data to the table goes on

     (Field name 1, field name 2, ...): Which field to give the value

    values ​​(value 1, value 2, ...): setting a specific value

  1, all of the fields inserted

    ① all field names written down

INSERT INTO table name (field 1, field name 2, 3 ... field name) the VALUES (value 1, value 2 and value 3);

    ② not write the field names, field names by default all

INSERT INTO table name VALUES (value 1, value 2 and value 3, ...);

  2, the data insertion portion

INSERT INTO table name (field 1, field name 2, ...) the VALUES (value 1, value 2, ...);

    Tips : Adding data field does not use NULL

  3 Notes

    ① inserted data to be same as the data type of the field

    ② If you do not define a column name after the table name, the default is to add value for all columns

    ③ In addition to the digital type, other types require the use of quotation marks (single or double quotation marks) due to

    ④ size of data to be within the predetermined range of the column, such as: the length can not be placed in a length 20 of column 10.

    ⑤ specified column or not null, null values ​​represent insertion

  4、  

  5、

  6、

Second, modify data

  Syntax :

set update table column name = value [where Conditional Expression];

    update table: the table name needs to be updated

       set: modify column values

  where: qualifying record is updated

  1, without modifying the condition data (to modify all rows)

update table set field = value;

  2, conditional modification data

update table set field where field name = value = value;

 

 

Third, delete data

  Syntax :

DELETE FROM table [WHERE conditional expression]

    If no where clause, all records MySQL table will be deleted, you can specify any condition in the where clause.

  1, delete data without conditions

delete from 表名;

  2, conditional deletion of data

delete from table where field = value;

  3, delete all records truncate table

truncate table 表名;

  4, the difference between truncate and delete

    •  truncate table table name - is recommended, a structure corresponding to delete the table, and then create a different table.
    •    delete from table - Delete all records, not recommended, how many records how many times the delete operation is executed. 

Guess you like

Origin www.cnblogs.com/niujifei/p/11573693.html