zoukankan      html  css  js  c++  java
  • mysql 中modify和change区别(以及使用modify修改字段名称报错)

    使用modify修改字段报错如下:

    mysql> alter table student modify name sname char(16);
    ERROR 1064 (42000): 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 'sname char(16)' at line 1

    经亲测modify与change的区别在于修改字段名称只能是用change,modify不能修改字段名称

    在网上看到很多人说change不能修改字段的类型,实际上是都可以的,只需要注意使用change修改字段类型的时候,即使不修改字段名称但是也要把原名称写上,否则会报错

    mysql> alter table student change name name varchar(32) not null;
    Query OK, 15 rows affected (0.03 sec)
    Records: 15 Duplicates: 0 Warnings: 0
    mysql> alter table student modify sname char(16);
    Query OK, 15 rows affected (0.16 sec)
    Records: 15 Duplicates: 0 Warnings: 0

    修改字段名称: (change)
    注意修改字段名称只能是用change,modify不能修改字段名称。

    mysql> alter table student change gender sex char(32) not null;
    Query OK, 15 rows affected (0.11 sec)
    Records: 15 Duplicates: 0 Warnings: 0
  • 相关阅读:
    linux top
    虚拟内存
    strcpy与strncpy
    C++ 踩内存
    MySQL -- 全文检索
    MySQL -- 全文检索(自然语言全文检索)
    MySQL -- innodb中cardinality是如何统计的
    MySQL -- Fast Index Creation
    python -- 生成器
    MySQL中模拟oracle中的rownum列
  • 原文地址:https://www.cnblogs.com/heaven-xi/p/10006525.html
Copyright © 2011-2022 走看看