zoukankan      html  css  js  c++  java
  • 1029 回顾

    昨日回顾

    1.表的操作

    create table 表名(
    	字段名 字段类型[字段约束]
    	....
    )charset=utf8
    

    字段类型

    数字

    整数

    tinyint
    smallint
    int		*********************
    mediumint
    bigint
    
    区别 :
    	取值的范围不一样
    	加上unsigned,代表只能取整数
    

    浮点型

    float
    double
    decimal(10,5)
    

    字符串类型

    char()	定长
    	身份证,手机号
    varchar()	变长
    	哈希密码
    
    区别:
    	1.char(4)  'ab  ' 占4个字节,剩余的不足字节用空字节补充
    	2.varchar(4) 'ab' 占3个字节,其中有两个是自身的大小,还有一个是记录字节的大小
    

    时间类型

    datetime**************

    年月日时分秒
    

    枚举

    enum
    gender enum('male','female') default 'female';
    

    列的约束(可选的参数)

    auto_increment	自增
    not null	不能为null
    primary key		主键索引
    default		默认值
    

    drop table 表名;
    

    删除字段名

    alter table 表名 drop 字段名;
    

    新增表的字段

    alter table 表名 add 列声明;
    alter table 表名 add 列声明 frist;
    alter table 表名 add 列声明 after 字段名;
    

    修改表的字段名

    alter table 表名 modify 字段名 字段类型[字段约束]
    alter table 表名 change 旧字段 新字段 字段类型[字段约束];
    

    show tables;
    

    操作数据行

    insert into 表名(列1,列2) values(值1,值2),(值1,值2);
    

    delete from 表名;
    	自增继续加1,一行行删除
    truncate 表名;
    	全选删除,自增键重新开始,速度快
    

    按条件删除

    delete from 表名 where id=10;
    delete from 表名 where id=10 and name='n';
    

    update 表名 set name='zekai',age=12;
    

    按条件修改

    update 表名 set name='zekai', age=15 where age=12 and num=10;
    

    select * from 表名; 	返回表中所有数据
    select 列名1,列名2 from 表名;
    

    按条件查找

    select * from where id=10;
    

    between...and...

    select * from 表名 id between 30 and 40;
    

    distinct去重

    select distinct name from t6;
    

    in查询

    select 
    

    like 模糊查询

    
    

    四则运算

    
    

    is null

    1.单表操作

    分组

    分组是将所有数据按照某个相同字段进行分类

    group by

    order

    limit

    2.多表操作

    外键

    3.mysql的备份

    create table department(
    				id int auto_increment primary key,
    				name varchar(32) not null default ''
    			)charset utf8;
    			
    			insert into department (name) values ('研发部');
    			insert into department (name) values ('运维部');
    			insert into department (name) values ('前台部');
    			insert into department (name) values ('小卖部');
    			
    			create table userinfo (
    				id int auto_increment primary key,
    				name varchar(32) not null default '',
    				depart_id int not null default 1,
    				constraint fk_user_depart foreign key (depart_id) references department(id)
    			)charset utf8;
    			
    			insert into userinfo (name, depart_id) values ('zekai', 1);
    			insert into userinfo (name, depart_id) values ('xxx', 2);
    			insert into userinfo (name, depart_id) values ('zekai1', 3);
    			insert into userinfo (name, depart_id) values ('zekai2', 4);
    			insert into userinfo (name, depart_id) values ('zekai3', 1);
    			insert into userinfo (name, depart_id) values ('zekai4', 2);
    			insert into userinfo (name, depart_id) values ('zekai4', 5);
    
  • 相关阅读:
    poj 1961 Period
    call 大佬 help7——kmp 补齐 循环节
    hdu 3746 Cyclic Nacklace
    poj 2406 Power Strings
    [Baltic2009]Radio Transmission
    poj 2752 Seek the Name, Seek the Fame
    hdu 3336 Count the string
    hdu 2594 Simpsons’ Hidden Talents
    hdu 1711 Number Sequence
    我在开发第一个Swift App过程中学到的四件事
  • 原文地址:https://www.cnblogs.com/fwzzz/p/11779546.html
Copyright © 2011-2022 走看看