MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 2443|回复: 1
打印 上一主题 下一主题

【奇怪的问题】mysql无法update字段的默认值是怎么回事?

[复制链接]
跳转到指定楼层
1#
发表于 2014-2-7 09:25:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
简要来说,就是某字段column_a在插入记录时没有赋值,之后就没法更新了。

具体如下:
两列的create table命令如下:
  `column_a` int(18) DEFAULT '100' COMMENT '无法update',
  `column_b` int(18) DEFAULT '0' COMMENT '可以update',

我插入一条数据,column_a没有赋值,column_b=123
insert table_name (column_b) values (123);

然后我发现该问题,想要更新column_a值,结果出错:
update table_name set column_a = 123213 where id = 1;
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 'column_a = 123213 where id = 1' at line 1

查询该记录column_a = 100, column_b = 123。
不知道什么原因,于是我写入column_b,发现column_b可以正常更新:
update table_name set column_b = 123213 where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

着实奇怪。。
mysql版本如下:
Server version: 5.1.54-1ubuntu4-log (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
发表于 2014-2-11 11:19:38 | 只看该作者
专门试了试,我这儿是可以的:
1 queries executed, 1 success, 0 errors, 0 warnings

Query: update a set column_a = 123213 where id = 1

1 row(s) affected

Execution Time : 0.021 sec
Transfer Time  : 0 sec
Total Time     : 0.022 sec
与默认值应该没有关系。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-6-14 02:40 , Processed in 0.062951 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表