MySQL 表数据类型更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6148979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:03:35  来源:igfitidea点击:

Table Data Type Alter

mysqldatabase

提问by swapnesh

I created a table named items and inserted name as int and provided the length as 255 type by mistake but now i wanted to alter the table structure and run the query as--

我创建了一个名为 items 的表并将名称插入为 int 并错误地提供了 255 类型的长度,但现在我想改变表结构并运行查询——

ALTER TABLE items ALTER COLUMN name varchar(255); but it is not altering the table what i need to change in the table.help plz

ALTER TABLE 项目 ALTER COLUMN name varchar(255); 但这并没有改变我需要在 table.help 中更改的表格

回答by diEcho

there are two ways

有两种方法

ALTER TABLE t1 CHANGE <column_name> <column_name> <type> 

note:you have to write column name twice OR

注意:你必须写两次列名或

ALTER TABLE t1 MODIFY <column_name> <type> ;

Reference

参考

回答by neocanable

try:

尝试:

alter table t1 modify column name varchar(255);

回答by royrui

Try:

尝试:

ALTER table items
MODIFY name varchar(255);