数据库
首页 > 数据库> > Addition, deletion, modification and query of MySQL

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':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) The 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); The 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'); The 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; The 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); The above result is success

 

‘deletion’:Delete from ‘table name’ ‘where’ conditional expression 1)delete some data    command:DELETE  FROM student
                    WHERE id=7; The above result is success   2)delete all data    command:DELETE FROM student The 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:

1)Update some data

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

The above result is success

 

2)Update all data

   command:UPDATE student
                   SET grade=80;

The above result is success

 

 

'query':Single table query

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

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);

  1)Simple query   Query all fields   command:SELECT id,name,grade ,gender
                   FROM student2; The above result is success      Query the specified part of the field    command:SELECT name,gender FROM student2; The above result is success   The amount of tasks is a little large, unfinished to be continued  

标签:student,success,Addition,result,above,MySQL,modification,data,name
来源: https://www.cnblogs.com/lixin666/p/15585071.html