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