数据库的增删改查
数据的基本操作:增(insert)删(delete)改(update)查(select);
1.添加数据(insert)
  insert into 表名(字段名1,字段名2) values (数据1,数据2);
  insert into 表名(name,tid) values ('李⽩','王维');
  insert into 表名(name,tid) values (''李⽩,'王维'),(''杜甫,'孟浩然'); 这是插⼊多条数据
  字段名和数据要⼀⼀对应;
  字符串和时间⽇期类型⽤单引号引起来;
  字段可以省略,但是要按顺序全字段数据插⼊;truncate删除数据
2.数据的删除(delete)
  delete from 表名删除表中的所有数据但是id不会重置
  truncate 表名:删除表中所有数据,标识所⽤值重置;
  delete from grade where id=4;  加上限制条件 where可以就指定删除哪⼀⾏
3.修改(update)
  update 表名 set 字段名=新值 [where id = 3];
  update grade set name='zhangsan';    这样写就把name字段下⾯数据全更改了
  update grade set name='php' where id =1; 这样写是指定name字段下的id是1的哪⼀⾏更改数据  update grade set name='php',title='aaa'  where id =1; 这是修改多条字段的信息
4.查询(select)
  select * from 表名;
  select *from grade; 这是查询表中所有字段下的数据
  select 字段1,字段2 from 表名
  select name,tid from grade;这是查询字段name和tid下的数据
  select 字段1 as ‘新名字’,字段2 as ‘新名字' from 表名
  select name as '姓名' , tid as '学号' from grade;  查询出来的结果给name和tid起个新名字显⽰;
4.1where条件(逻辑and or ⽐较>、<、=、>=、<=、<>不等于)
  select * from 表名 where 字段1>值 and 字段2<;值;
  select*from grade where chengji>=10 and chengji<=15;
  (1).where条件中between and  这个其实就是等于 chengji>=10 and chengji<=15;
  select * from 表名 where 字段 between 75 and 90;
  select*from grade where chengji between 10 and 20;
  (2).空条件查询
  select * from 表名 where 字段 IS NULL;(IS NOT NULL)  select*from grade where chengji IS NULL;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。