0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[MySQL]カラムのデータ型を変更

Posted at

データ型を変更する方法をよく忘れてしまうので、メモとして残します。

テストテーブル

mysql> DESC employee;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| code  | varchar(45) | NO   | UNI | NULL    |                |
| name  | varchar(45) | YES  |     | NULL    |                |
| age   | int(11)     | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

codeカラムのデータ型をintに変更

mysql> ALTER TABLE employee MODIFY code int NOT NULL;

mysql> ALTER TABLE employee MODIFY code int; ## NOT NULL制約を外したりすることも可能
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?