登录
首页 >  数据库 >  MySQL

我如何修改现有的MySQL列的数据类型?

来源:tutorialspoint

时间:2023-08-23 08:22:23 119浏览 收藏

小伙伴们对数据库编程感兴趣吗?是否正在学习相关知识点?如果是,那么本文《我如何修改现有的MySQL列的数据类型?》,就很适合你,本篇文章讲解的知识点主要包括。在之后的文章中也会多多分享相关知识点,希望对大家的知识积累有所帮助!

ALTER COMMAND is used to modify an existing MySQL column’s data type. Following is an example which demonstrates that how we can use this command to modify column’s data type −

mysql> describe testing\G
*************************** 1. row ***************************
  Field: id1
   Type: int(11)
   Null: NO
    Key: PRI
Default: 0
  Extra:
*************************** 2. row ***************************
  Field: name
   Type: char(30)
   Null: YES
    Key:
Default: NULL
  Extra:
2 rows in set (0.05 sec)

从上述DESCRIBE查询中,我们可以看到Name列的数据类型为CHAR(30)。现在借助以下查询的帮助,我们可以将其更改为VARCHAR(20) −

mysql> ALTER TABLE Testing MODIFY Name Varchar(20);
Query OK, 4 rows affected (0.60 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> Describe Testing\G;
*************************** 1. row ***************************
  Field: id1
   Type: int(11)
   Null: NO
    Key: PRI
Default: 0
  Extra:
*************************** 2. row ***************************
  Field: Name
   Type: varchar(20)
   Null: YES
    Key:
Default: NULL
  Extra:
2 rows in set (0.15 sec)

Now the data type has been modified to VARCHAR(20).

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《我如何修改现有的MySQL列的数据类型?》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>