mysql表操作

  1. 引擎
    1. 引擎种类
      1. innodb : 支持事物, 支持行锁, 支持表锁,  支持外键, 适合表结构复杂, 写入更新操作较大的场景
      2. myisam : 不支持事物, 只支持表锁, 优点是查询速度较快, 适合只读操作,或者写入操作很少的场景
      3. memory : 数据存在内存中, 读写较快, 断电即消失
    2. 指定引擎:
      1. create table t1( id int) engine = innodb;
      2. alter table t1 engine = innodb;
      3. 在配置文件 mysql.ini 中修改    
    1. 创建表: create table stu(id int,name char(5), sex enum('male','female'));
    2. 查看表结构:
      1. desc stu:
      2. show create table stu:
    3. 数据类型:
      1. 数值类型
        1. 整数: int  bigint
        2. 小数: float ,double , decimal(M, D) M:精度, D:小数点后面的位数
      2. 日期和时间:
        1. date 年月日
        2. time 时分秒
        3. year 年
        4. datetime 年月日时分秒
        5. timestamp  
      3. 字符串
        1. char
        2. varchar
      4. 单选和多选
        1. 单选 : enum
        2. 多选 : set    
    4. 完整性约束:
      1. default
      2. not null
      3. unique
      4. primary key
        1. create table class(id int primary key auto_increment, )  
      5. foreign key  
        1. create table stu(id int primary key auto_increment, name varchar(10), cid int, foreign key(cid) references class(id) on delete cascade on update cascade); 设置级联更新和级联删除
    5. 修改表结构:
      1. alter table stu rename student
      2. alter table stu add course_id int;
      3. alter table stu drop course_id;
      4. alter table stu modify course_id bigint;
      5. alter table stu change course_id courses char(5);
    6. 删除表
      1. drop table stu    
原文地址:https://www.cnblogs.com/zhangjian0092/p/11685317.html