MYSQL数据库常用语句
Posted Anderson_An
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL数据库常用语句相关的知识,希望对你有一定的参考价值。
1.查看数据库服务器已有的数据库
show databases;
2.查看数据库(school)定义的信息
show create database school;
3.连接数据库
use school;
4.查看当前连接的数据库
select database();
5.数据库创建
create database school;
6.数据库修改
alter database school character set utf8;
7.数据库删除
drop database school;
8.查看当前库已有表
show tables;
9.创建表
create table student( id int, name varchar(20), age int );
10.查看表定义信息
show create table student;
11.数据库的增、删、改(这里我是在图形化软件dataGrip里添加的数据)
/*增*/
insert into student(`num`,`name`,`age`,`class`,`math`) values (3,"赵子龙",20,3,100);
/*删*/
delete from student where name = "张三";
/*改*/
update student set age = 100 , num = 6 where name = "赵子龙";
12.数据库的查询(比较多)
/*查询表所有数据*/
select * from student;
/*查询表带条件数据*/
select * from student where age = 100;
/*查询表某个字段数据*/
select age,name from student;
/*查询表数据总数*/
select count(1) from student;
/*查询表数据带条件数目*/
select count(1) from student where age = 20 and class = 2; /*且*/
select count(1) from student where age = 20 or class = 2; /*或*/
/*查询表数据所有人数带条件(age)总和*/
select sum(age) from student;
/*查询表数据带条件(age)的平均数*/
select avg(age) from student;
/*查询表数据带条件(age)的平均数并且改名(as)为age_avg*/
select avg(age) as age_avg from student;
/*查询表数据按条件(class)进行分组求总数*/
select count(1) from student from group by class;
13.数据库分页查询
/*按10个一页查询第二页数据*/
select * from student limit 10,2;
/*按正序排*/
select * from student order by id;
/*按倒序排*/
select * from student order by id desc;
---------------------
以上是关于MYSQL数据库常用语句的主要内容,如果未能解决你的问题,请参考以下文章
[AndroidStudio]_[初级]_[配置自动完成的代码片段]
[AndroidStudio]_[初级]_[配置自动完成的代码片段]