mysql的CRUD

一、介绍

CRUD即增加(Create)、查询(Retrieve)、更新(Update)、删除(Delete)四个单词的首字母缩写。

In computing, CRUD is an acronym for create, Retrieve, update, and delete. It is used to refer to the basic functions of a database or persistence layer in a software system.

C reate new records

R etrieve existing records

U pdate existing records

D elete existing records.

平常我们说的系统开发中的增改查删可以用CURD来表示 增加:Create 修改:Update查找:Read删除:Delete 外国人喜欢CRUD,表示增查改删: 增加:Create读取查询:Retrieve更新:Update删除:Delete

二、insert和repleace 

repleace 与insert基本上一样

不一样的是:insert 如果指定主键,唯一约束存在,则报错,replace则修改

insert into stu value(null,'李四',22,'女','郑州');

insert stu(name,address) values('李平','北京'),('刘阳','上海'),('赵强','广州');

replace into stu values(null,'王五',25,'女','河南省郑州市');

 三、delet删除

drop database 数据库
drop table 表白
alter table stu drop column 行
删除表中的数据记录用:delete from 表名 where 条件
truncate table  stu//截断数据 删除数据
-- 删除数据 delete 和 truncate 区别
/*
delete 一条记录一条记录删除,删除所有的时候,效率低,但它灵活 可以加上条件
会触发删除触发器
truncate 直接截断数据,auto_increment 恢复默认 , 不触发删除触发器,
也没有影响行,删除所有的时候,效率高,只能删除截断数据
*/

四、update修改update zcx set sage=18;

-- 修改数据
select * from stu;
-- update 表名 set 列名=值,列名2=值2 ... where 条件表达式 ;

update stu set age = 20,gender = '男' where name = '王五';

update stu set age = 22,gender = '男' where id = 4;

-- 修改郑州地址的 人员年龄增加一岁
update stu set age = age + 1 where address like '%郑州%';

like '%李'李结尾的
like '李%'李开头的
like '%李%'包含李的

五、select查询

查询一个段里所有属性长度
select *from length(trim(addr)) from stu;
select *from student;
alter table student add ssort int unsigned default 1;
--基本查询
select *from student;
select sno,sname,ssort fromstudent order by ssort asc;
asc//降序
desc//升序
limit 限制结果
--查询限制结果行
select sno,sname from student limit 3000;
select sno,sname from student limit 0,3;
--查询别名
select sno,sname from student stu;
select sno,sname from student as stu;
select sno as 年龄,sname 姓名 from student as stu;
--0-10
select sno as 年龄,sname 姓名,round(rand()*10)from student as stu;
select sno,sname from student order by rand() limt 2;//效率低
select sno,sname from student where sno in (201201,212333);

-- 分页 每页3条记录,显示第二页
select id,name from stu limit 0,3; -- 第一页
select id,name from stu limit 3,3; -- 第二页

select id ,name from stu limit 9,3;


-- 第n页 limit n*3-3,3

当前页*每页条数-每页条数,每页条数

show colums from student;

desc studnt;



 insert 15:12:38

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值