Addition, deletion, modification and query of MySQL

The source of this article is 白居不易

Before the specific work, we should first establish a database containing the data table “student”.(http://www.cnblogs.com/heyangblog/p/7624591.html)

Addition, deletion, modification and query of MySQL

'Addition':Add data 1)Add data for all data in the table    Specify all field names in the Insert statement    Example:INSERT INTO student(id,name,grade)
                  VALUES(1,'zhangshan',98) Addition, deletion, modification and query of MySQLThe above result is success     The field name is not specified in the Insert statement   If no field name is specified, the order of the added values should be exactly the same as that of the fields in the table.   Example:INSERT INTO student
                 VALUES (2,'lisi',62); Addition, deletion, modification and query of MySQLThe above result is success   2)Adds data to the specified field of the table    Add data for the specified field, that is, add values to only some fields, while the values of other fields are the default values when the table is defined.    Example:INSERT INTO student(id,name)
                  VALUES(3,'wangwu'); Addition, deletion, modification and query of MySQLThe above result is success It can be seen that the grade field value of the new record is null because it indicates the grade value when adding, and the system will automatically add the default value.   3)Other ways to write Insert statements    Example:INSERT INTO student
                  SET id=4,name='zhaoliu',grade=72; Addition, deletion, modification and query of MySQLThe above result is success

 

4)Add multiple pieces of data at the same time    Example:INSERT INTO student VALUES
                 (5,‘lilei’,99),
      (6,'hanmeimei',87),
                 (8,'poly',76); Addition, deletion, modification and query of MySQLThe above result is success

 

‘deletion’:Delete from ‘table name’ ‘where’ conditional expression 1)delete some data    command:DELETE  FROM student
                    WHERE id=7; Addition, deletion, modification and query of MySQLThe above result is success   2)delete all data    command:DELETE FROM student Addition, deletion, modification and query of MySQLThe above result is success   ‘modification’:Update data Before executing the following statements, use the insert statement to insert the following data into the student table: Addition, deletion, modification and query of MySQL

1)Update some data

   command:UPDATE student
                    SET name=‘caocao’,grade=50
                    WHERE id=1;

Addition, deletion, modification and query of MySQLThe above result is success

 

2)Update all data

   command:UPDATE student
                   SET grade=80;

Addition, deletion, modification and query of MySQLThe above result is success

 

 

'query':Single table query

Before the following operations, let's create a new data table student2

Addition, deletion, modification and query of MySQL

Then insert the following data into the student2 table:

INSERT INTO student2(name,grade,gender)

VALUES ('songjiang',40,'男'),('wuyong',100,'男'),('qinming',90,'男'),('husanniang',88,'女'),('sunerniang',66,'女'),('wusong',86,'男'),('linchong',92,'男'),('yanqing',90,NULL);

Addition, deletion, modification and query of MySQL   1)Simple query   Query all fields   command:SELECT id,name,grade ,gender
                   FROM student2; Addition, deletion, modification and query of MySQLThe above result is success      Query the specified part of the field    command:SELECT name,gender FROM student2; Addition, deletion, modification and query of MySQLThe above result is success   The amount of tasks is a little large, unfinished to be continued  
上一篇:Python鼻子配置文件仅允许在其中指定一次


下一篇:Google Earth Engine——GFS全球天气预报模型数据集:384小时的预测,预测间隔为3小时,以6小时的时间分辨率进行(每天更新4次)