sql 更改列数据类型_SQL查询更改列数据类型

sql 更改列数据类型

Datatype of the column in SQL can be changed using the ALTER TABLE command. It can also be used to ADD, DELETE or MODIFY columns in already existing tables. It can also be used to ADD or DROP constraints in the SQL database.

可以使用ALTER TABLE命令更改SQL中列的数据类型。 它也可以用来添加,删除或修改现有表中的列。 它也可以用于在SQL数据库中添加或删除约束。

Here we are going to only talk about changing the datatype of the column.

在这里,我们只讨论改变列的数据类型

For doing the task the following syntax is used,

为了执行此任务,使用了以下语法,

    ALTER TABLE table_name
    MODIFY COLUMN column_name datatype;

Let's understand the above-mentioned concept with the help of example.

让我们借助示例来了解上述概念。

Let us consider the table "People".

让我们考虑表“ People”。

SRNAMEAGEBIRTH_YEAR
1Mona451975
2Kanishka182002
3Hardik221998
SR 名称 年龄 出生年
1个 莫娜 45 1975年
2 鹿冢 18 2002年
3 哈迪克 22 1998年

Here we are going to change the datatype for birth_year from int to year datatype.

在这里,我们将birth_year的数据类型从int更改为year数据类型。

SQL Query:

SQL查询:

ALTER TABLE People
MODIFY COLUMN birth_year year;

After the commitment of this program code, the column birth_year is now of type year and can only store birth_year in the two or four-digit format.

提交该程序代码后, birth_year列现在为year类型,并且只能以两位或四位格式存储birth_year 。

翻译自: https://www.includehelp.com/sql/query-to-change-column-datatype.aspx

sql 更改列数据类型

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值