MySQL --2數據操作
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數據操作