如何更改 MySQL 列定义?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1595372/
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 14:19:19  来源:igfitidea点击:

How to change MySQL column definition?

mysqlalter-table

提问by Mask

I have a mySQL table called test:

我有一个名为 test 的 mySQL 表:

create table test(
    locationExpect varchar(120) NOT NULL;
);

I want to change the locationExpect column to:

我想将 locationExpect 列更改为:

create table test(
    locationExpect varchar(120);
);

How can it be done quickly?

怎样才能快速完成?

回答by mikej

Do you mean altering the table after it has been created? If so you need to use alter table, in particular:

您的意思是在创建表后更改表吗?如果是这样,您需要使用alter table,特别是:

ALTER TABLE tablename MODIFY COLUMN new-column-definition

e.g.

例如

ALTER TABLE test MODIFY COLUMN locationExpect VARCHAR(120);

回答by Niranjan Vaddi

Syntax to change column namein MySql:

MySql 中更改列名的语法:

alter table table_name change old_column_name new_column_name data_type(size);

Example:

例子:

alter table test change LowSal Low_Sal integer(4);

回答by Daniel Rikowski

This should do it:

这应该这样做:

ALTER TABLE test MODIFY locationExpert VARCHAR(120)