2.DML

16 篇文章 0 订阅

添加数据(Insert)

修改数据(Update)

删除数据(Delete)

DML-添加数据

mysql> insert into employee(id,workno,name,gender,age,idcard,entrydate) values(1,'1','itcast','男',10,'123456789012345678','2000-01-01');
ERROR 1054 (42S22): Unknown column 'gender' in 'field list'
mysql> insert into employee(id,workno,name,gendef,age,idcard,entrydate) values(1,'1','itcast','男',10,'123456789012345678','2000-01-01');
Query OK, 1 row affected (0.00 sec)

mysql> select * from 
Display all 760 possibilities? (y or n) 
mysql> select * from employee;
+------+--------+--------+--------+------+--------------------+------------+
| id   | workno | name   | gendef | age  | idcard             | entrydate  |
+------+--------+--------+--------+------+--------------------+------------+
|    1 | 1      | itcast | 男     |   10 | 123456789012345678 | 2000-01-01 |
+------+--------+--------+--------+------+--------------------+------------+
1 row in set (0.00 sec)




mysql> insert into employee value (3,'3','张无忌','男',18,'123456789123456789','2025-10-15');
Query OK, 1 row affected (0.00 sec)

mysql> select * from employee;
+------+--------+-----------+--------+------+--------------------+------------+
| id   | workno | name      | gendef | age  | idcard             | entrydate  |
+------+--------+-----------+--------+------+--------------------+------------+
|    1 | 1      | itcast    | 男     |   10 | 123456789012345678 | 2000-01-01 |
|    2 | 2      | itcast2   | 男     |   21 | 123456789012345678 | 2000-01-01 |
|    3 | 3      | 张无忌    | 男     |   18 | 123456789123456789 | 2025-10-15 |
+------+--------+-----------+--------+------+--------------------+------------+
3 rows in set (0.00 sec)

多字段同时插入

DML-修改-删除

更新记录

mysql> update employee set name = 'itheima' where id =1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from employee;
+------+--------+-----------+--------+------+--------------------+------------+
| id   | workno | name      | gendef | age  | idcard             | entrydate  |
+------+--------+-----------+--------+------+--------------------+------------+
|    1 | 1      | itheima   | 男     |   10 | 123456789012345678 | 2000-01-01 |
|    2 | 2      | itcast2   | 男     |   21 | 123456789012345678 | 2000-01-01 |
|    3 | 3      | 张无忌    | 男     |   18 | 123456789123456789 | 2025-10-15 |
+------+--------+-----------+--------+------+--------------------+------------+
3 rows in set (0.00 sec)


mysql> select * from employee;
+------+--------+-----------+--------+------+--------------------+------------+
| id   | workno | name      | gendef | age  | idcard             | entrydate  |
+------+--------+-----------+--------+------+--------------------+------------+
|    1 | 1      | itheima   | 男     |   10 | 123456789012345678 | 2000-01-01 |
|    2 | 2      | itcast2   | 男     |   21 | 123456789012345678 | 2000-01-01 |
|    3 | 3      | 张无忌    | 男     |   18 | 123456789123456789 | 2025-10-15 |
+------+--------+-----------+--------+------+--------------------+------------+
3 rows in set (0.00 sec)

mysql> update employee set name='小糟',gendef='女' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from employee;
+------+--------+-----------+--------+------+--------------------+------------+
| id   | workno | name      | gendef | age  | idcard             | entrydate  |
+------+--------+-----------+--------+------+--------------------+------------+
|    1 | 1      | 小糟      | 女     |   10 | 123456789012345678 | 2000-01-01 |
|    2 | 2      | itcast2   | 男     |   21 | 123456789012345678 | 2000-01-01 |
|    3 | 3      | 张无忌    | 男     |   18 | 123456789123456789 | 2025-10-15 |
+------+--------+-----------+--------+------+--------------------+------------+
3 rows in set (0.00 sec)

 不带where条件 会更新表中所有记录 
mysql> update employee set entrydate ='2008-01-01';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select * from employee;
+------+--------+-----------+--------+------+--------------------+------------+
| id   | workno | name      | gendef | age  | idcard             | entrydate  |
+------+--------+-----------+--------+------+--------------------+------------+
|    1 | 1      | 小糟      | 女     |   10 | 123456789012345678 | 2008-01-01 |
|    2 | 2      | itcast2   | 男     |   21 | 123456789012345678 | 2008-01-01 |
|    3 | 3      | 张无忌    | 男     |   18 | 123456789123456789 | 2008-01-01 |
+------+--------+-----------+--------+------+--------------------+------------+
3 rows in set (0.00 sec)

DML 删除数据

mysql> delete from employee where gendef='女';
Query OK, 1 row affected (0.00 sec)

mysql> delete from employee;
Query OK, 2 rows affected (0.00 sec)

mysql> select * from employee;
Empty set (0.00 sec)



  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值