首页 > 数据库技术 > 详细

MySQL--数据的增删改(查在下一节单讲)

时间:2017-09-06 22:38:49      阅读:254      评论:0      收藏:0      [点我收藏+]
- 增加
insert into ... values(...) 
insert into 表名;values()要包含全部的数据; 
insert into 表名(字段);values()只需要列举对应的数据;
| 全列插入
insert into students
values(0,‘郭靖‘,1,‘蒙古‘,‘2016-1-2‘);
| 部分插入
insert into students (name, birth)
values ("王二", “2008-08-08”);
| 多行插入
insert into students (name, birth)
values ("刘备", "1000-08-08"),
("张飞", "1000-08-08");
- 修改(更新)
| 根据where后面的条件,修改字段
update 表名 set 列1=值1... where 条件(相同的数据)
update students set age=21;
update students set age=18 where id=1;
update students set age=10,gender=4 where id=1;
- 删除
| 物理删除
delete from 表名 where 条件;
delete from students where id=1;
| 逻辑删除
# 数据没有真实删除,
# 只是添加了一个是否在使用中的标记
--添加一个is_delete字段,数据类型为二进制
alter table students add is_delete bit;
--给字段添加默认值
alter table students add is_delete bit;
--修改字段的值,来正确标记是否在使用中
alter table students set is_delete=1 where id=1;

MySQL--数据的增删改(查在下一节单讲)

原文:http://13269293.blog.51cto.com/13259293/1963244

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!