MySQL数据库中对表中的数据进行增删改

DML:对表中的数据进行增删改

  1. 对某个表增加一行数据:insert into stu(name,age,score)values('wang',19,90.8);
    除了数字类型以外,其他的类型都需要用单引号或双引号引用起来。
mysql> insert into stu(name,age,score)values('wang',19,90.8);
Query OK, 1 row affected (0.01 sec)

mysql> select * from stu;
+----+------+------+-------+------------+
| id | name | age  | score | address_id |
+----+------+------+-------+------------+
|  0 | wang |   19 | 90.80 |       NULL |
+----+------+------+-------+------------+
1 row in set (0.00 sec)
  1. 对表中的一行数据删除:DELETE FROM stu WHERE NAME='王五',如果后面不添加条件,则是默认删除表中所有的数据。
mysql> DELETE FROM stu WHERE NAME='wang';
Query OK, 1 row affected (0.32 sec)

mysql> select * from stu;
Empty set (0.00 sec)
  1. 修改表中数据:UPDATE stu SET NAME='王五' WHERE age=19,若满足条件的数据不唯一,则全部修改。
mysql> UPDATE stu SET NAME='li' WHERE age=19;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from stu;
+----+------+------+-------+------------+
| id | name | age  | score | address_id |
+----+------+------+-------+------------+
|  0 | li   |   19 | 90.80 |       NULL |
+----+------+------+-------+------------+
1 row in set (0.00 sec)

你可能感兴趣的:(数据库)