mysql存储更新接收数据类型_如何将mysql字段类型从INT更改为VARCHAR会影响先前作为INT存储的数据...

在更改列类型之前,让MySQL服务器进入严格模式,并确保varchar(n)列具有足够大的n,以便在将所有整数转换为字符串时保存。如果你不是在严格模式,那么MySQL将

silently truncate your data to fit your string size:

If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR column that exceeds the column’s maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode.

mysql> set sql_mode = 'STRICT_ALL_TABLES';

mysql> alter table table_sample change col_sample col_sample varchar(6);

你会得到一个很好的错误消息,像这样:

ERROR 1406 (22001): Data too long for column 'col_sample' at row ...

如果你的整数不是所有适合你的varchar。

当然,在尝试更改表之前,您将对数据库进行新的验证备份。通过验证我的意思是你已经成功地恢复您的备份到测试数据库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值