MySQL study notes 2 - DML

DML (Data Manipulation Language, which is the operation record table (add, delete, change)!)

1. Insert Data

* INSERT INTO table name (name column 1, column name 2, ...) the VALUES (column value 1, the column value 2, ...);
> given in the table column name to be inserted, the other is not specified column is equivalent to a null value is inserted, the insertion record always insert a row, you can not be half lines.
> Column corresponding to column gives the values after VALUES, and the sequence number of values must be specified in the previous.
* INSERT INTO table VALUES (column value 1, the column value 2, ...);
> not given column to be inserted, then insert indicates all columns.
> Must be a number of values of the number of table columns.
> Order of values, given the same order of the columns when the table must be created.

 

// insert all columns
 INSERT  INTO STU (the above mentioned id, name, Age, Gender
)VALUES(
'ITCAST_0001', 'zhangSan', 28, 'male');

// insertion part of the column, the column is not specified the default is NULL
 the INSERT  the INTO STU (ID, name
)VALUES(
'ITCAST_0001', 'zhangSan');

// do not give insert a column, then the default is to insert all columns! The same order as the column values to create a table with
 the INSERT  the INTO STU the VALUES (
 ' ITCAST_0001 ' , ' zhangsan ' , 28 , ' MALE ' );

2. Modify Data

* The UPDATE SET column name table column value 1 = 1, 2 = column name column value 2, ... [the WHERE condition]
* (condition optional):
> conditions must be a boolean value or expression: UPDATE t_person SET gender = 'M', the WHERE Age = Age +. 1 SID = '. 1';
> operator: =, =, <>, >, <,> =, <=, BETWEEN ... AND, IN! (...), IS NULL, NOT , OR, AND

// the age data is equal to 18 in the gender MALE
 the UPDATE STU the SET gender = ' MALE '  the WHERE age = 18 ;

3. Delete Data

* DELETE FROM table name (WHERE condition);

* TRUNCATE TABLE table name: TRUNCATE is DDL statement, which is to delete drop the table, re-create the table, and can not be rolled back!

// delete data ITCAST_0001 id equal to
 * the DELETE  the FROM STU the WHERE id = ' ITCAST_0001 ' ;

Guess you like

Origin www.cnblogs.com/silentteller/p/11795970.html