sql中数据处理:
一.添加新数据!
插入单行记录
1.create table box(
name varchar(30) not null,
id int not null primary key,
student varchar(20),
gender char(2) default 0 comment ‘0男:1女‘
);
insert into box(name, id, student) values(‘xiaohong‘,123,‘123‘),(‘bingxin‘,565,‘334‘);
select*from box;
插入新数据:insert into 表名(列名)values (列表参数)也可加,(列表参数);
插入多行数据:insert into <表名> select <select语句>
insert into games select year+12,city from games;
insert inti Students (studenyname,studenyid) select studenyname+2,studenyid from Students.
二.更新新数据。
1.update 表名 set 要改的值 where <过滤的条件>
create table box3(
name varchar(30) not null,
id int not null primary key,
student varchar(20),
gender char(2) default 0 comment ‘0男:1女‘
);
insert into box3(name, id, student) values(‘minxing‘,365,‘668‘), (‘lunxun‘,778,‘388‘);
update set box3 name=‘xiaotao‘,id=‘596‘ where student=‘668‘;
delete from box3 where id=‘365‘ and student=‘388‘;
select*from box3;
2.删除数据
delete from 表名 where <过滤条件>
delete from box3 where id=‘596‘;
delete from box3 where id=‘335‘and/or name=‘xiaotao‘;
一。查询的基本结构:
select 列
from 表名
where (过滤的)
group by 以....来分组
having 判定...条件
order by(排序)asc升序,desc降序
二:
查找:select 列名 from表名
select name,student,subject from box;
取别名:select name‘姓名‘ ,subject‘奖项‘ from box;
返回限定行数查询:
select top 5 student from box(查询第一条到第五条)
三模糊查询:
select *from box where limit 0,4(o是从0行开始,4是指长度)
select*from box where like ‘%liu%‘;
select age from student order by age desc limit 0,8;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。