网上找到好多 获取字段的默认值 但是感觉很复杂 还报错 最后找到一个 就一句 真不知道那些复杂的是做什么用的。。
获取默认值我已经知道了 
show columns from `表明` where Field='字段名' 获取字段的设置信息 
想知道 怎么修改默认值 网上找到的是这个
 alter table tablename alter column drop default; (若本身存在默认值,则先删除)alter table tablename alter column set default 't5';(若本身不存在则可以直接设定)但是一直提示错误 
求教!!

解决方案 »

  1.   

    alter table tablename modify column colName colType .... default 't5';重新修改下定义 不就完了
      

  2.   

    呃。。看不懂 能否注释下
    我想修改 aaaa表中的 bbbb字段的 默认值 为cccc
    语句是什么样的呢?
      

  3.   

    create table x (id int, f int default 5);mysql> create table x (id int, f int default 5);
    Query OK, 0 rows affected (0.05 sec)mysql> desc x;
    +-------+---------+------+-----+---------+-------+
    | Field | Type    | Null | Key | Default | Extra |
    +-------+---------+------+-----+---------+-------+
    | id    | int(11) | YES  |     | NULL    |       |
    | f     | int(11) | YES  |     | 5       |       |
    +-------+---------+------+-----+---------+-------+
    2 rows in set (0.02 sec)mysql> alter table x modify f int default 3;
    Query OK, 0 rows affected (0.06 sec)
    Records: 0  Duplicates: 0  Warnings: 0mysql> desc x;
    +-------+---------+------+-----+---------+-------+
    | Field | Type    | Null | Key | Default | Extra |
    +-------+---------+------+-----+---------+-------+
    | id    | int(11) | YES  |     | NULL    |       |
    | f     | int(11) | YES  |     | 3       |       |
    +-------+---------+------+-----+---------+-------+
    2 rows in set (0.02 sec)mysql>
      

  4.   

    alter table aaaa change bbbb bbbb not null default 'cccc';
      

  5.   

    alter table tbname modify column int default 'f1';
      

  6.   

    报错
    [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null default 666' at line 1
      

  7.   

     alter table 表名 alter 字段名 drop default; (若本身存在默认值,则先删除)alter table 表名 alter 字段名 set default  修改值;(若本身不存在则可以直接设定)最后还是自己搞定的..无语