简体   繁体   English

MySQL alter table-将TINYINT更改为SMALLINT

[英]MySQL alter table - changing a TINYINT to a SMALLINT

I have the following database with two tables (excuse my ugly format): 我有以下带有两个表的数据库(不好用的格式):

TABLE_A : Id TINYINT, PRIMARY KEY (Id)
TABLE_B : Id TINYINT, FOREIGN KEY (Id) REFERENCES TABLE_A (Id)

I would like to modify Id so that it's a SMALLINT rather than a TINYINT. 我想修改Id,以便它是SMALLINT而不是TINYINT。 Here are a couple failed attempts: 这是几次失败的尝试:

mysql> ALTER TABLE TABLE_A MODIFY Id SMALLINT
ERROR 1025 (HY000): Error on rename of '.\testdb\#sql-bcc_16' to '.\testdb\table_a' (errno: 150)

mysql> ALTER TABLE TABLE_B DROP FOREIGN KEY (Id)
ERROR 1025 (HY000): Error on rename of '.\testdb\table_b' to '.\testdb\#sql2-bcc-16' (errno: 152)

Does anyone know what's going on here? 有人知道这是怎么回事吗?

Use below queries 使用以下查询

mysql> ALTER TABLE Price MODIFY Id SMALLINT

mysql> ALTER TABLE Sale MODIFY Id SMALLINT

mysql> ALTER TABLE Phone MODIFY Id SMALLINT

I also answered it at MySQL alter table generating "error on rename" long time back... but you are not replying there... 我也在MySQL alter table上回答了很久,它生成了“重命名错误” ……但是您没有在那儿回复……

Here in your case it will be 在你的情况下

mysql> ALTER TABLE TABLE_A MODIFY Id SMALLINT

mysql> ALTER TABLE TABLE_B MODIFY Id SMALLINT

Update 更新资料

check Help with: ERROR 1025 (HY000): Error on rename of .... (errno: 150) .. Might help you.. 检查帮助:错误1025(HY000):重命名....(错误号:150)时出错

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用充满数据的数据库从tinyint更改为smallint - Changing from tinyint to smallint with a database full of data 一位数的MySQL数据类型-tinyint(1)或smallint(1)或int(1) - Mysql datatype for single digit - tinyint(1) or smallint(1) or int(1) 用于人体身高的MySQL变量(tinyint或smallint) - MySQL Variable for human height (tinyint or smallint) MySQL中SMALLINT,TINYINT等的默认大小 - Default size of SMALLINT, TINYINT etc. in MySQL 更新/更改具有约550万行(TINYINT到SMALLINT)的MySQL表中的列的数据类型的最佳和最安全的方法是什么? - What is the best and safest method to update/change the data type of a column in a MySQL table that has ~5.5 million rows (TINYINT to SMALLINT)? MySQL 中的 tinyint、smallint、mediumint、bigint 和 int 有什么区别? - What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL? 如何在cakephp3中使用phinx迁移更改列时为tinyint,smallint类型设置可见长度? - How to set visible length for type tinyint,smallint while alter column using phinx migration in cakephp3? 在 Mysql 中将列类型从 tinyInt 更改为 Varchar - ALTER COLUMN TYPE from tinyInt to Varchar in Mysql 将列类型从INT更改为SMALLINT和TINYINT后,MyISAM表中的空间增加了 - Space increased in MyISAM table after change column type from INT to SMALLINT and TINYINT 使用html复选框和PHP更改MySQL TINYINT(1) - Changing MySQL TINYINT(1) with an html checkbox and PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM