java MySQL所有语句
——————取自姚老师笔记
一。数据定义语言DDL(create、alter、drop)
(1)数据库
create database 库名;
drop database 库名;
alter database 库名 character set gbk;
(2)表
create table 表名(属性名 数据类型,..) ;
drop table 表名;
alter table 表名
a.修改表名 alter table 旧表名 rename [to] 新表名;
b.新增字段 alter table 表名 add column 字段名 类型 [after 字段|frist];
c.修改字段 alter table 表名 change 旧字段名 新字段名 新类型;
d.删除字段 alter table 表名 drop column 字段名;
(3)存储过程
a.创建 create procedure 过程名([in|out|inout] 参数名称 参数类型)
begin
过程体
end;
call调用
b.删除:drop procedure 过程名;
c.修改alter
(4)存储函数
a.创建 create function 函数名(参数名称 参数类型)
returns 返回类型
begin
函数体
end;
select 调用
b.删除:drop function 过程名;
c.修改:alter
(5)用户
a.创建用户:create user '用户名'@'主机名' identify by '密码'
b.删除用户:drop user '用户名'@'主机名';
二。数据操作语言DML(insert,delete,select,update)
1.增加:insert into 表名 values(值);
(1)向表中所有的字段插入数据:
insert into user values(1,'姚天雪');
insert into user(id,name) values(1,'姚天雪');
(2)向表中指定的字段插入数据:
insert into user(name) values('李萌');
(3)向表中插入多条记录(常用)
insert into user values(2,'姜立柱'),(3,'李萌萌'),(4,'姚甜雪');
2.删除:delete from 表名 [where 条件];
(1)删除所有数据
delete from user;
(2)删除带条件数据
delete from user where id=1;
delete from user where name='李萌';
3.修改:update 表名 set 字段=值 [where 条件]
(1)修改所有的数据
update user set id=5;
update user set id=6,name='姚老师';
(2)修改带条件的数据
update user set name='李萌' where id=3;
(3)练习:
将id为4的老师名字修改成姚明:update user set name='姚明' where id=4;
将李萌老师的id改成10:update user set id=10 where name='李萌';
将id>2的老师的id都改成90:update user set id=90 where id>2;
4.查询(****************************):对表中的数据没有任何修改
(1)查询所有的字段
select * from user;
(2)查询指定的字段
select name from user;
(3)查询带条件的数据 where
a.比较=、<、<=、〉、〉=、!=、^、!>、!<
select * from user where id!=10;
select * from user where id>=3;
b.关键字查询in、not in
select * from user where id in(2,4);//只查2和4,不是2-4
select * from user where id in(20);
select * from user where id not in(2,3,4);
c.范围查询between and、not between and
select * from user where id between 1 and 3;//查1-3(包括1和3),不是1和3
select * from user where id not between 1 and 3;//查不在1-3之间的
d.like模糊查询:%在哪哪里随意 _在哪哪必须有 没有符号必须没有
<1>%:可以匹配0到多个
select * from user where name like '%雪';//雪字前面可有可无;雪字后面必须没有
<2>_:只能匹配1个
select * from user where name like '_雪';//雪子前面必须一个;雪字后面必须没有
e.null、is not null空值查询
select * from user where id is null;
select * from user where id is not null;
f.and和or多条件查询 and(&&) or (||)
select * from user where id=5 and name='张雪晴';
select * from user where id=5 or name='姚甜雪';
(4)order by:以..排序
select * from user order by id [asc];按照id从小到大排序
select * from user order by id desc;按照id从大到小排序
需求:将姓名中带雪字的老师查询出来并按照id从大到小排序
select * from user where name like '%雪%' order by id desc;
(5)group by:以..分组(一般和聚合函数count(*)、sum(字段)、max(字段)、min(字段)、avg(字段))
a.统计各个id有多少人:select id,count(*) from user group by id;
b.统计各个id的老师年龄的总和:select id,sum(age) from user group by id;
c.统计各个id年龄最大的老师:select id,max(age) from user group by id;
d.统计各个id年龄最小的老师:select id,min(age) from user group by id;
e.统计各个id的平均年龄:select id,sum(age)/count(*) from user group by id;
select id,avg(age) from user group by id;
三。数据控制语言DCL(grant,revoke)
(1)grant sth to sb:grant 权限类型 on 数据库名.表名 to '用户名'@'主机名' [with grant option];
(2)revoke sth from sb:revoke 权限类型 on 数据库名.表名 from '用户名'@'主机名';
四。其他语句
数据库导出:mysqldump -u用户名 -p密码 数据库名 表名>本地>本地地址(D:/a.sql)
数据库导入: mysql -u用户名 -p密码 数据库名 表名 <本地地址(D:/a.sql)
五。约束
主键: primary key
外键: foreign key references
唯一:unique key
非空:not null
自增长:auto_increment
默认:default
java MySQL所有语句相关推荐
- java mysql查询语句_Mysql查询语句执行过程
Mysql查询语句执行过程 Mysql分为server层和存储引擎两部分,或许可以再加一层连接层 连接层(器) Mysql使用的是典型的C/S架构.连接器通过典型的TCP握手完成连接. 需要注的是, ...
- java mysql ddl语句_DDL语句的实例详解
2017-07-11 12:47:30 1.查询当前连接下的数据库 SHOW DATABASES; 2.创建新的数据库 CREATE DATABASE [IF NOT EXISTS] java03 [ ...
- java mysql executequery_java - 无法使用executeQuery()发出数据操作语句
java - 无法使用executeQuery()发出数据操作语句 在MySQL中,我有两个表,tableA和tableB.我正在尝试执行两个查询: executeQuery(query1) exec ...
- MySQL中定义fk语句_MySQL基础篇/第3篇:MySQL基本操作语句.md · qwqoo/MySQL-Review - Gitee.com...
### 第3篇:MySQL基本操作语句 - MySQL基础操作 #### 排序检索数据 - 之前的数据没有进行排序,其是按照默认在数据表中的数据返回的 - SELECT语句的ORDER BY 子句进行 ...
- mysql等价语句是_Mysql基本语句(个人笔记)
mysql基本操作语句 1 数据库的基本操作 create database doem default charset utf8; -- 创建数据库 字符编码 utf8 show database; ...
- mysql 查询语句_MySQL相关(一)- 一条查询语句是如何执行的
前言 学习一个新知识最好的方式就是上官网,所以我先把官网贴出来 MySQL官网 (点击查阅),如果大家有想了解我没有说到的东西可以直接上官网看哈~目前 MySQL 最新大版本为8.0,但是鉴于目前应用 ...
- JAVA+MySQL综合笔记
Java+MySQL综合运用笔记 一.Java连接使用mysql的5个思路过程 首先导入JDBC驱动jar包放到lib文件夹里面. 1.加载驱动方法 ①注册驱动:DriverManager.reg ...
- 【Java+MySQL】使用JDBC连接MySQL 8.0数据库
一.Java MySQL 8.0连接驱动包 下载链接:https://pan.baidu.com/s/1YFOImz0dCHtzIajSFq9xgg?pwd=boul 提取码:boul [IDEA]导 ...
- Java mysql获取行数_java – MySQL查询获取球体中的行(X,Y,Z坐标)?
我正在制作一个名为Minecraft with Bukkit API的游戏插件. 我有一个名为Reinforcements的数据库表,其中包含以下字段:x integer,y integer,z in ...
最新文章
- ICE BOX 配置,使用----第一篇
- pandas创建复合索引dataframe仿真数据集实战(create a multiIndex dataframe)
- linux下面子目录绑定域名的方法,.htaccess绑定子域名到子目录方法
- 从Github一开源项目ADSEC【学习域渗透攻防基础】
- Java并发——结合CountDownLatch源码、Semaphore源码及ReentrantLock源码来看AQS原理
- 【速看,双100%】剑指 Offer 14- I. 剪绳子 I
- MySQL调用mongodb事务回滚_SpringBoot整合MongoDB,在多数据源下实现事务回滚。
- 利用modelarts和物体检测方式识别验证码
- Python第六次作业
- python 教程 第二十一章、 扩展Python
- 罗技无法使用计算机上的配置文件,Win10专业版罗技无线鼠标无法使用咋办?
- P6615 Kruskal + 构造
- 每日简报 4月22日简报新鲜事 每天一分钟 了解新鲜事
- 免费的视频转Gif软件
- js获取传统节假日_js能获取一年中所有的法定节假日,有这样的程序吗?
- 腾讯云服务器配置LNMP环境并安装wordpress
- Pikachu漏洞练习平台----验证码绕过(on server) 的深层次理解
- 建立您的启动:自定义会议视图
- 数据库ER图该怎么画
- 电子天平的检定和检定结果的影响因素
热门文章
- mapbox样式规范(style)
- 简单的书签服务LinkDing
- 绿联扩展坞拆解_拆解报告:UGREEN绿联2A1C三口多功能拓展坞
- 高手如何做全网整合营销推广?全网营销方法和策略有哪些?
- Traceback (most recent call last):异常
- Python全栈(八)Flask项目实战之8.CMS后台轮播图管理
- 线性代数(19)——行列式(下)
- PowerPMAC技术培训------2、PowerPMAC产品介绍
- c7200-adventerprisek9.124-9.T.bin
- 浙大计算机各个实验室 详细介绍(持续更新)