代码小白产品经理,要懂的mysql语言(四)

代码小白产品经理,要懂的mysql语言(一)

代码小白产品经理,要懂的mysql语言(二)

代码小白产品经理,要懂的mysql语言(三)

25.索引操作语法

查看:show index from B 或 show create table B

alter table 表名 drop index 索引名

删除:alter table B drop index M、drop index 索引名 on 表名

添加:alter table 表名 add index/nuique 索引名(列名)

-> alter table B add index xm (xing,ming)

-> alter table B add unique xm(xing,ming)

添加主键索引:alter table 表名 add primary key(列名称)

-> alter table B add primary key (xing)

删除主键索引:alter table 表名 drop primary key(列名称)

-> alter table B drop primary key

26.常用函数

floor:整数

-> select name_id,shop_price,floor(market_price) from goods

rand:返回0到1内的随机数

-> select rand()*5+5

-> select floor(rand()*5+5)

position:获取位置

left:截取出字符串左边的几个字节

-> select left (email,3) from B

-> select left(email,position('@' in email()-1) from B

日期时间

select now():返回当前时间

-> select now ()

-> select date_formart(now(),'%Y/M')

27.事务概念

roll back:回滚,即撤销,发生在事务之前,过程的数据均不混淆

    -> create table account <

    -> id int

    -> name char(10)

    -> money int

    -> >engine innodb charset utf8

    -> insert into account values (1,'zhangsan',5000)

    -> insert into account values (2,'lisi',5000)

    -> select * from account

    -> update account set money=money+500 where id=2

    -> start transaction

    -> select * from account

    -> update account set money=money+500 where id=2

    -> update account set money=money-500 where id=1

    -> commit

    ->

    -> start transaction

    -> update account set money=money+500 where id=2

    -> update account set money=money-500 where id=1

    -> rollback

    ->

    -> select * from account

    -> alter table account change money

    -> money int unsigned

    -> select * from account

    -> update account set money=money-10000 where id=1

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,277评论 0 0
  • 接下来的一些内容,我们需要提前学一些简单的sql语句,方便大家理解接下来的知识。 DDL—数据定义语言(Creat...
    不排版阅读 490评论 0 1
  • 1.A simple master-to-slave replication is currently being...
    Kevin关大大阅读 6,423评论 0 3
  • 常用语句: sql/plus sqlplus 'amdocs/Amdocs.Jx.China.110#@ysdb1...
    好好学习的蜗牛阅读 3,484评论 0 0
  • 今天下午第一、二、三节课上了围棋,我最喜欢围棋,老师先给我们讲了一个小故事,老师给我们讲了一个喜羊羊理发的故事,然...
    李嘉宝1阅读 335评论 0 0

友情链接更多精彩内容