zoukankan      html  css  js  c++  java
  • MySQL使用alter修改表的结构

    SQL语句

        DLL        数据定义语言

            create,drop

        DML     数据操纵语言

            insert,delete,select,update

        DCL        数据控制语言

            grant,revoke

            
    使用ALTER TABLE修改表结构

    (1)修改表名

    ALTER TABLE <表名> RENAME <新表名>

    mysql> alter table game_account rename account;
    Query OK, 0 rows affected (0.05 sec)

    (2)修改表的搜索引擎

    mysql> alter table account engine=MyISAM;
    Query OK, 0 rows affected (0.05 sec)
    Records: 0  Duplicates: 0  Warnings: 0


    查看表的信息

    mysql> show create table accountG;
    *************************** 1. row ***************************
           Table: account
    Create Table: CREATE TABLE `account` (
      `game_name` char(15) NOT NULL,
      `game_password` char(25) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    1 row in set (0.00 sec)
    ERROR: 
    No query specified

    (3)添加字段

    ALTER TABLE <表名> ADD <字段名称> <字段定义>

    后面添加:

    mysql> alter table account add game_sex enum("M","F") not null;


        
    前面添加:

    mysql> alter table account add game_address varchar(20) not null default "huabei" first;
    Query OK, 0 rows affected (0.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    中间添加:

    mysql> alter table account add game_money int after game_name;
    Query OK, 0 rows affected (0.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0


    (4)删除字段

    ALTER TABLE <表名> drop <字段名称>

    mysql> alter table account drop game_wei;
    Query OK, 0 rows affected (0.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    (5)修改字段名称及字段定义

    ALTER TABLE <表名> CHANGE <旧字段> <新字段名称> <字段定义>

    mysql> alter table account change game_zhang wei char(25) not null;
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    mysql> alter table account change wei wei varchar(60)  ;
    Query OK, 0 rows affected (0.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0


    (6)修改字段定义

    ALTER TABLE <表名> MODIFY <字段名称> <字段定义>

    mysql> alter table account modify wei int ;
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    mysql> alter table account modify wei int  not null ;
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0


     

  • 相关阅读:
    [大牛翻译系列]Hadoop(4)MapReduce 连接:选择最佳连接策略
    [大牛翻译系列]Hadoop(2)MapReduce 连接:复制连接(Replication join)
    [大牛翻译系列]Hadoop(3)MapReduce 连接:半连接(Semijoin)
    [大牛翻译系列]Hadoop(1)MapReduce 连接:重分区连接(Repartition join)
    Springboot启动流程分析
    行为型模式模板&策略&命令
    Springboot自动装配原理
    Springboot零配置原理
    行为型模式中介者&迭代器&访问者
    结构型模式组合&享元
  • 原文地址:https://www.cnblogs.com/heian99/p/11972289.html
Copyright © 2011-2022 走看看