mysql的库名、表名大小写敏感;字段大小写不敏感;
创建数据库info: create database info;
展示数据库: show databases;
连接数据库: use info;
展示info包含的表: show tables;
创建表: create table stuinfo(
id int,
name varchar(20));
修改表t1为t2:rename table t1 to t2;
增加字段(sal,comm):alter table t1 add sal int;
alter table t1 add column comm float;
修改字段(name)属性:alter table t1 modify name varchar(40);
查看表t1:desc t1;
修改字段comm名称及属性:alter table t1 change comm comm2 double;
删除字段comm2:alter table t1 drop comm2;
查看表的创建方式:show create table t1;
查询语句:
查询stuinfo: select *from stuinfo;
增加数据: insert into stuinfo(id,name) values(1,‘啦啦啦’);
insert into stuinfo values(1,‘啦啦啦’);
删除数据: delete from stuinfo where id=1;注意,这里可能会报错需要我们先执行 set sql_safe_updates=0来修改下数据库模式,然后就可以了
排序: select *from stuinfo order by id desc 升序asc降序desc
一些常用的函数:
concat(a,b) 连接字段a和b:concat(‘sss’,‘fafaf’) 为sssfafaf
substr(a,b) 从a截取第b位及之后,这里的b从1开始,就是a的第一位索引为1,substr(‘abc’,1) 为abc ; substr(‘abc’,2)为bc
upper 转大写
lower 转小写
length 求字节长度 length(‘kkk’)为3 ;length(‘啊’)为3
trim 默认去除两边的空格 trim(’ 啊啊 ')为啊啊
trim(‘aa’ from ‘aa啊啊aa’)为啊啊
lipad 左填充 lipad(‘aaa’,5,‘1’)为aaa11