zoukankan      html  css  js  c++  java
  • MySQL alter修改语句

    1.alter用法修改数据表的名字
    rename语法: 修改数据表的名字rename 旧的表 to 新的表;
    mysql> rename table tanks to Tanks;

    利用alter命令修改数据表
    语法:alter table 当前表名 rename to 新表名;
    mysql> alter table Tanks rename to TANKS;

    查看tanks的表结构
    mysql> desc tanks;
    +--------+--------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +--------+--------------+------+-----+---------+-------+
    | id | int(11) | NO | PRI | 0 | |
    | name | varchar(100) | NO | | NULL | |
    | skills | varchar(255) | NO | | NULL | |
    | price | int(11) | NO | | NULL | |
    +--------+--------------+------+-----+---------+-------+
    4 rows in set (0.01 sec)

    查看创建table的语句
    mysql> show create table tanks;
    +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table | Create Table |
    +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | tanks | CREATE TABLE tanks (
    id int(11) NOT NULL DEFAULT '0',
    name varchar(100) NOT NULL,
    skills varchar(255) NOT NULL,
    price int(11) NOT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
    +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)

    mysql>

    2.修改数据表的字段
    Introductrion 具体的介绍信息

    添加字段
    Introduction 具体的介绍信息
    alter指令
    语法 :
    alter table 表名 add 字段名 字段的数据类型(长度) 额外的字段属性;

    alter table tanks add introduction varchar(255) not null;

    3.添加指定位置的字段
    summoner_skills ENUM('flush','fire') not null default 'flush' # flush 闪现 ghost 幽灵疾步

    插入到数据表中
    添加alter指令,指定插入到那个字段的后面
    alter table tanks add summoner_skills ENUM('flush','fire') not null default 'flush' after skills;

    4.一次性添加多个字段
    英雄的阵营、图片头像
    camp
    pic

    修改表字段的语句,指定插入在price字段后面
    alter table tanks add camp varchar(50) after price, add pic varchar(255) after camp;

    5.修改字段的类型
    语句 pic的varchar改为char类型
    alter table 表名 change 旧字段名 新字段名 新数据类型;

    alter table tanks change pic pic_url char(20);

    6.alter删除table的字段
    alter table 表名 drop 字段;
    alter table tanks drop introduction;

  • 相关阅读:
    Python Socket 网络编程之粘包现象
    Socket 通信流程和 Python 网络编程基础
    WAF 技术原理
    Python 反射机制(自省)
    Python中创建对象的内部流程、metaclass和type类
    理解Python可迭代对象、迭代器、生成器
    Python 面向对象编程 总结
    python类的继承
    【macOS】关闭mac的Microsoft AutoUpdate
    tampermonkey修改页面音频播放地址
  • 原文地址:https://www.cnblogs.com/w1sh/p/14944021.html
Copyright © 2011-2022 走看看