分享

MySQL

 python_lover 2020-12-03

一:数据类型:

整数类型(5种):
tinyint:byte
smallint:short
mediumint:
int:
bigint:long

浮点型和定点型:
float:
double:

decimal(m,i):

日期与时间类型:
year:yyyy 表示年份
date:yyyy-mm-dd表示日期
time:hh-mm-ss表示时间
datetime:yyyy-mm-dd hh-mm-ss表示日期和时间
timestamp:yyyy-mm-dd hh-mm-ss表示日期和时间,取值范围小

字符串和二进制类型:
char
varchar

binary
varbinary
blob表示二进制大数据,pdf文档,图片等
tinytext,text,mediumtext,longtext表示大文本数据
enum
set 表示字符串的对象
bit 位

二:数据表的操作:

查看数据表:
desc [表名]

show table [表名]

修改数据表:
修改表名:alter table [旧表名] rename to [新表名];

修改字段名:alter table [表名] change [旧字段名] [新字段名] [新字段名]

修改字段的数据类型:alter table [表名] modify [字段名] [数据类型]

添加字段:alter table [表名] add [新字段名] 数据类型(约束)

删除字段:alter table [表名] drop [字段名]

修改字段的排列位置:alter table [表名] modify [字段名1] [数据类型] first/after [字段名2]

删除数据表:drop table [表名]

添加数据: insert into 表名 values( ),( ),( );

更新数据: updata 表名 set id=01,name=' ' where id=1;

删除数据: delete from 表名 where id<5;

表的约束:
主键约束:
primary key:单字段约束,多字段约束

非空约束:
...not null

唯一约束:
...unique

默认约束:
...default 0

索引:是为了高效率查找特定的数据,提高查询速度

删除索引:
alter table drop index 索引名

drop index 索引名 on 

创建索引:

创建表时创建索引:

普通索引:index([字段名])

唯一索引:unique index [unique_id(id asc)]//asc,升序 desc,降序

全局索引:fulltext index [fulltext_id(id)]

单列索引:index [single_name(name(20))]

多列索引:index multi(id,name(20))

空间索引:spatial index nm(name)

在已建立表上创建索引:

create index

create [unique/spatial/fulltext] index [索引名] on 表名(id(10),name(20))

alter table

alter table 表名 add [unique/spatial/fulltext] index 索引名(id(20) asc)

单表查询:
简单查询:
select语句:
按条件查询:
where
in
between and
null
distinct
like:'%' 通配符查询;'_' 通配符查询
and(多条件查询)
or
高级查询:select
聚合函数:
count(),sum(),avg(),max(),min()
查询结果排序:
select * from s1 order by id adc,item desc
分组查询:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多