首页 > 数据库技术 > 详细

MySQL --2数据操作

时间:2018-01-23 14:14:23      阅读:169      评论:0      收藏:0      [点我收藏+]
#查询
select from 表名
例:
select
from students;


#增加
全列插入:insert into 表名 values(...)
例:
insert into students values(0,"黄蓉",‘1990-01-01‘,0,0);

缺省插入:insert into 表名(列1,...) values(值1,...)
例:
insert into students ("name","gender") values("郭靖",1);

同时插入多条数据:insert into 表名 values(...),(...)...;
例:
insert into students values(0,"小龙女","1992-02-03",0,0),(0,"杨过","1991-01-01",1,0);

或insert into 表名(列1,...) values(值1,...),(值1,...)...;
例:
insert into students("name","gender") values("雕",1),("郭襄",0);

#Mysql 可以同时插入多条数据,Mysql 特有的功能。


#修改
update 表名 set 列1=值1,... where 条件
若不加 where 条件,则修改所有列;

例:
update students set birthday="1980-02-01" where name="郭靖";

#修改多个values:
update students set name="蓉儿" birthday="1988-01-01" where name="黄蓉";


#删除
#物理删除
delete from 表名 where 条件
例:delete from students where id=5;

#逻辑删除

update students isdelete=1 where ...; //增加isDelete列,默认值为0,删除则将值改成1
例:
update students isDelete=1 where id=6;

查询时只查询isDelete=0的数据达到删除效果
select * from students where isDelete=0;

MySQL --2数据操作

原文:http://blog.51cto.com/1126228/2064192

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