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

    1增加两个字段:

    1. mysql> create table id_name(id int,name varchar(20));  
    2. Query OK, 0 rows affected (0.13 sec)  
    3.   
    4.   
    5. mysql> alter table id_name add age int,add address varchar(11);  
    6. Query OK, 0 rows affected (0.13 sec)  
    7. Records: 0  Duplicates: 0  Warnings: 0  
    8.   
    9. mysql> desc id_name;  
    10.   
    11. +---------+-------------+------+-----+---------+-------+  
    12. | Field   | Type        | Null | Key | Default | Extra |  
    13. +---------+-------------+------+-----+---------+-------+  
    14. | id      | int(11)     | YES  |     | NULL    |       |  
    15. name    | varchar(20) | YES  |     | NULL    |       |  
    16. | age     | int(11)     | YES  |     | NULL    |       |  
    17. | address | varchar(11) | YES  |     | NULL    |       |  
    18. +---------+-------------+------+-----+---------+-------+  
    19. rows in set (0.00 sec)  
    20.   
    21. 2.删除两个字段  
    22. mysql> alter table id_name drop column age,drop column address;  
    23. Query OK, 0 rows affected (0.14 sec)  
    24. Records: 0  Duplicates: 0  Warnings: 0  
    25.   
    26. mysql> desc id_name;  
    27. +-------+-------------+------+-----+---------+-------+  
    28. | Field | Type        | Null | Key | Default | Extra |  
    29. +-------+-------------+------+-----+---------+-------+  
    30. | id    | int(11)     | YES  |     | NULL    |       |  
    31. name  | varchar(20) | YES  |     | NULL    |       |  
    32. +-------+-------------+------+-----+---------+-------+  
    33. rows in set (0.00 sec)  
    34.   
    35. 3.插入  
    36. mysql> insert into id_name values (1,'qustdjx');  
    37. Query OK, 1 row affected (0.00 sec)  
    38. 4.查询看一下  
    39. mysql> alter table id_name add age int,add address varchar(11);  
    40. Query OK, 1 row affected (0.07 sec)  
    41. Records: 1  Duplicates: 0  Warnings: 0  
    42.   
    43. mysql> select * from id_name;  
    44. +------+---------+------+---------+  
    45. | id   | name    | age  | address |  
    46. +------+---------+------+---------+  
    47. |    1 | qustdjx | NULL | NULL    |  
    48. +------+---------+------+---------+  
    49. 1 row in set (0.00 sec)  
    50. 5.新增字段并插入  
    51. mysql> insert into id_name values(2,'qust',14,'山东');  
    52. Query OK, 1 row affected (0.00 sec)  
    53.   
    54. mysql> select * from id_name;  
    55. +------+---------+------+---------+  
    56. | id   | name    | age  | address |  
    57. +------+---------+------+---------+  
    58. |    1 | qustdjx | NULL | NULL    |  
    59. |    2 | qust    |   14 | 山东    |  
    60. +------+---------+------+---------+  
    61. rows in set (0.00 sec)  
    62.   
    63.    


    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;  //修改一个字段的名称,此时一定要重新指定该字段的类型

  • 相关阅读:
    深入JAVA注解之属性注解
    深入JAVA注解之方法注解
    C# 启动外部程序的几种方法
    在.NET中实现彩色光标/动画光标和自定义光标[转]
    C#实现汉诺塔问题
    ExecuteNonQuery()返回值注意点
    在VS2012下不安装VS2010编译VS2010的工程
    Windows 窗体的.Net 框架绘图技术
    使用DataSet Datatable 更新数据库的三种方式
    C#.net 之货币转换
  • 原文地址:https://www.cnblogs.com/mingyue1818/p/4151606.html
Copyright © 2011-2022 走看看