zoukankan      html  css  js  c++  java
  • MySQL

    一:数据类型:

    整数类型(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
    分组查询:

  • 相关阅读:
    java ArrayList存储基本类型
    java ArrayList的几种方法使用
    java ArrayList的基本使用
    java 猜数字
    java Random随机生成一个数
    java Scanner输入数字、字符串
    java 构造方法
    java this的应用
    java pravite关键字的使用
    云计算服务
  • 原文地址:https://www.cnblogs.com/lookabc/p/12005541.html
Copyright © 2011-2022 走看看