最近开始学习mySQL基本语句,记录一下。
增删查改
show databases; 查看所有数据库
create databases xxx; 创建xxx数据库
drop databases xxx; 删除xxx数据库
use xxx; 进入xxx数据库
create table users(id int,name varchar(50)); 创建users表,整型字段id,字符串name
show tables; 展示所有表
insert into users values(1,‘java’); 插入数据
insert into users values(2,‘mysql’);
select id,name from users; 展示users表的id name对应字段
select * from users; 展示users表的所有字段
select id,name from users where id = 1; 精准查找
select id,name from users where id>1 and id<5;
update users set name = ‘c++’ where id =5; 更新字段
delete from users where id>=6; 删除某行
模糊查询like
select id,name from users where name like ‘%a%’;
SQL聚合函数
Max(字段名) Min Sum Avg Count求总量
Distinct 除去重复
GROUP BY 按xx成组
ORDER BY 按xx排序
MySQL索引
索引可以大大提高查询速度,但同时降低更新表的速度。
ALTER table tableName ADD INDEX indexName(columnName) 添加普通索引
有时间整理下