MySql相关的理论

1. 什么是Mysql

是一个数据库(存储数据的仓库) 可以存储的内容有  文字 图片 音效等等

2. Mysql语句

DDL    数据库操作语言  对数据库的操作   create(添加数据库)  alter(修改数据库)  drop  (删除数据库)
DCL    数据控制语言    对数据操作       grant、revok 
DQL    数据查询语言    对数据操作 查询    select(查询)   
DML   数据操作语言    对数据操作增改删       insert(添加数据) update(修改数据) delete(删除数据)

3. 创建数据库

create database 数据库名

4 使用数据库

use 数据库名

5 修改数据库编码

alter database 数据库名 CHARSET = UTF8 

6 对数据库重命名

rename database 源数据库名 to 更改后数据库名

7 显示所有数据库名

show databases   

8 删除数据库名

drop database 数据库名

9 创建表格

create table users (
	userid int,
	username VARCHAR(20),
	useraddress varchar(20),
	userphone varchar(20)
)

10 表格添加数据

添加单条数据 
举例
   insert into 表格名 (userid,username,useraddress,userphone) VALUES (1,'张三','北京海淀','11110')
添加多条数据
举例
   insert into 表格名 values(1,'张1','北京海淀4','111'),(2,'张2','北京海淀2','2222'),(3,'张3','北京海淀3','333333')

11 修改表格数据

修改所有数据
	update 表格名 set 要修改对象 ='胃不是吧'
修改单条数据
	update 表格名 set 要修改对象 ="脉动" where 参照对象 = 3
	update users set username="脉动" where userid = 3

12 删除表格数据

删除单条数据
	 delete from 表格名 where 删除参照对象 = 
删除多条/区间
	delete from 表格名 where 删除参照对象 >=4 and userid<=6	-- 比如这个删除的是id大于4且小于6之间的
全部删除
delete from 表格名

13 varchar 和 char 的区别

	char类型是固定字节数  
	varcahr类型是可以改变字节数   

14 产看表格

show tables

15 产看创建表的mysql语句

show create table 表格名

16 产看表结构

desc 表格名

17 修改表格结构

alert table 表格名 add 修改对象 char(2)

18 查询

select * from 表格名

19 查询所有表格数据

select * from 表格名
select * from 表格名 where 查询对象 = 

20 范围查询 in and or

select * from 表格名 where  查询对象>=30 and score <=80 -- and  查询年龄在大于30小于50的数据
select * from 表格名 where 查询对象 between 50 and 80 -- and 查询年龄在大于30小于50的数据
select * from 表格名 where 查询对象 in (50,80) -- in 查询年龄在80岁的数据
select * from 表格名 where 查询对象= '男' or gender = '女' -- OR 查询性别男和女的第一次出现数据

21 排序查询

select * from 表格名 ORDER BY 查询对象 asc   -- 升序
select * from 表格名 ORDER BY 查询对象 desc --  降序

22 聚合函数 count max min avg sum

select count(*) from 表格名 GROUP BY 查询对象       -- 用于算总数 以及 对数据进行分页 总的数据数
select MAX(查询对象) FROM 表格名  -- 找最大的数
select Min(查询对象) FROM 表格名 -- 找最小的数
select sum(查询对象) FROM 表格名 -- 求和
select avg(查询对象) FROM 表格名 -- 平均数(返回结果浮点数)

23 like 模糊查询

select * from 表格名 where  查询对象 like '%明%' -- 搜索名字里全部带明的
select * from 表格名 where 查询对象  like '%明' -- 搜索名字里叫明的
select * from 表格名 where  查询对象 like '明%' -- 搜索名字里姓名的

select * from 表格名 where 查询对象 like '明_' -- _代表占一个字符 搜索结果为明** 列如明刚
select * from 表格名 where 查询对象 like '_明' -- 搜索结果为**明 列如 小明
select * from 表格名 where 查询对象 like '__明_' -- 搜索结果为*明* 例如王明珂

24 常见数据类型

整数   int long
浮点   double float
字符   char varchar
文本    text
日期类型  datatime   timestamp

25 多表查询

内连接 inner join
外连接 left join / right join	
全连接 full join

26 取别名(as)

语法:select * from student as at
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值