zoukankan      html  css  js  c++  java
  • MySQL中的表中增加删除字段

     

    1增加两个字段:

    复制代码
    mysql> create table id_name(id int,name varchar(20));
    Query OK, 0 rows affected (0.13 sec)
    
    
    mysql> alter table id_name add age int,add address varchar(11);
    Query OK, 0 rows affected (0.13 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc id_name;
    
    +---------+-------------+------+-----+---------+-------+
    | Field   | Type        | Null | Key | Default | Extra |
    +---------+-------------+------+-----+---------+-------+
    | id      | int(11)     | YES  |     | NULL    |       |
    | name    | varchar(20) | YES  |     | NULL    |       |
    | age     | int(11)     | YES  |     | NULL    |       |
    | address | varchar(11) | YES  |     | NULL    |       |
    +---------+-------------+------+-----+---------+-------+
    4 rows in set (0.00 sec)
    
    2.删除两个字段
    mysql> alter table id_name drop column age,drop column address;
    Query OK, 0 rows affected (0.14 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> desc id_name;
    +-------+-------------+------+-----+---------+-------+
    | Field | Type        | Null | Key | Default | Extra |
    +-------+-------------+------+-----+---------+-------+
    | id    | int(11)     | YES  |     | NULL    |       |
    | name  | varchar(20) | YES  |     | NULL    |       |
    +-------+-------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)
    
    3.插入
    mysql> insert into id_name values (1,'qustdjx');
    Query OK, 1 row affected (0.00 sec)
    4.查询看一下
    mysql> alter table id_name add age int,add address varchar(11);
    Query OK, 1 row affected (0.07 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> select * from id_name;
    +------+---------+------+---------+
    | id   | name    | age  | address |
    +------+---------+------+---------+
    |    1 | qustdjx | NULL | NULL    |
    +------+---------+------+---------+
    1 row in set (0.00 sec)
    5.新增字段并插入
    mysql> insert into id_name values(2,'qust',14,'山东');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from id_name;
    +------+---------+------+---------+
    | id   | name    | age  | address |
    +------+---------+------+---------+
    |    1 | qustdjx | NULL | NULL    |
    |    2 | qust    |   14 | 山东    |
    +------+---------+------+---------+
    2 rows in set (0.00 sec)
    
     
    复制代码

    1.增加一个字段
    alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL; //增加一个字段,默认为空
    alter table user add COLUMN new2 VARCHAR(20) NOT NULL;  //增加一个字段,默认不能为空  www.2cto.com  
     
    2.删除一个字段
    alter table user DROP COLUMN new2;   //删除一个字段
     
    3.修改一个字段
    alter table user MODIFY new1 VARCHAR(10);  //修改一个字段的类型
     
    alter table user CHANGE new1 new4 int;  //修改一个字段的名称,此时一定要重新指定该字段的类型

    http://blog.csdn.net/qustdjx/article/details/8875827

  • 相关阅读:
    application.properties /application.yml官网查看配置;springboot application.properties 官网查看,info yml 查看;springboot.yml查看info;springboot.yml查看Actuator监控中心info
    Clion 教程书写Hello World,C语言开发;Clion 的C语言开发
    Host is not allowed to connect to this MySQL server---------------->windows10
    @RequestBody jackson解析复杂的传入值的一个坑;jackson解析迭代数组;jackson多重数组;jakson数组
    windows10 搭建Dubbo
    无DNS解析环境下部署Vcenter6.7
    常用联想网络连接
    Linux 不重启扫描存储磁盘
    WWN,WWNN,WWPN三者的区别
    HDFS、Ceph、GFS、GPFS、Swift 等分布式存储技术的特点和适用场景
  • 原文地址:https://www.cnblogs.com/fengff/p/11805088.html
Copyright © 2011-2022 走看看